Skip to content

Commit

Permalink
fixed godoc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Sep 10, 2023
1 parent 182ee75 commit 4cec26c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 28 deletions.
17 changes: 10 additions & 7 deletions iso8601/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ func parseNumber(b []byte, start, width int) (v int) {
return
}

/*
* Basic Extended
* 20121224 2012-12-24 Calendar date (ISO 8601)
* 2012359 2012-359 Ordinal date (ISO 8601)
* 2012W521 2012-W52-1 Week date (ISO 8601)
* 2012Q485 2012-Q4-85 Quarter date
*/
// ParseDate attempts to parse a given byte slice representing a date in
// various supported ISO 8601 formats. Supported formats include:
//
// Basic Extended
// 20121224 2012-12-24 Calendar date (ISO 8601)
// 2012359 2012-359 Ordinal date (ISO 8601)
// 2012W521 2012-W52-1 Week date (ISO 8601)
// 2012Q485 2012-Q4-85 Quarter date
//
// The function returns an implementation of DateLike or an error if the parsing fails.
func ParseDate(b []byte) (DateLike, error) {
n, d, err := parseDate(b)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions iso8601/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ import (
"time"
)

// ParseDateTime attempts to parse a given byte slice representing combined date, time,
// and optionally timezone offset in supported ISO 8601 formats. Supported formats include:
//
// Basic Extended
// 20070301 2007-03-01
// 20070301T1300Z 2007-03-01T13:00Z
// 20070301T1300Z 2007-03-01T13:00Z
// 20070301T1300+0100 2007-03-01T13:00+01:00
// 20070301T1300-0600 2007-03-01T13:00-06:00
// 20070301T130045Z 2007-03-01T13:00:45Z
// 20070301T130045+0100 2007-03-01T13:00:45+01:00
// ... and other combinations
//
// The function returns a time.Time structure representing the parsed date-time, adjusted
// for the parsed timezone offset if provided. If no timezone is specified, the time is
// returned in UTC.
//
// In the absence of a time zone indicator, Parse returns a time in UTC.
//
// If parsing fails, an error is returned.
func ParseDateTime(b []byte) (time.Time, error) {
n, d, err := parseDate(b)
if err != nil {
Expand Down
28 changes: 19 additions & 9 deletions iso8601/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ import (
"time"
)

// fraction: (\d+)(?:[.,](\d{1,9}))?
// durationTime: (?:${fraction}H)?(?:${fraction}M)?(?:${fraction}S)?
// durationDate: (?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?
// duration: ^([+\u2212-])?P${durationDate}(?:T(?!$)${durationTime})?$
// ParseDuration attempts to parse a given byte slice representing a duration in the
// ISO 8601 format. Supported formats align with the regular expression patterns:
//
// NOTE: According to the ISO 8601-1 standard, weeks are not allowed to appear
// together with any other units, and durations can only be positive. As extensions
// to the standard, ISO 8601-2 allows a sign character at the start of the string, and
// allows combining weeks with other units. If you intend to use a string such as
// P3W1D, +P1M, or -P1M for interoperability, note that other programs may not accept it.
// fraction: (\d+)(?:[.,](\d{1,9}))?
// durationTime: (?:${fraction}H)?(?:${fraction}M)?(?:${fraction}S)?
// durationDate: (?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?
// duration: ^([+-])?P${durationDate}(?:T(?!$)${durationTime})?$
//
// Examples of valid durations include:
//
// PnYnMnDTnHnMnS (e.g., P3Y6M4DT12H30M5S)
// PnW (e.g., P4W)
//
// According to the ISO 8601-1 standard, weeks are not allowed to appear together
// with any other units, and durations can only be positive. However, as extensions
// to the standard, ISO 8601-2 allows a sign character at the start of the string and
// permits combining weeks with other units. If using a string such as P3W1D, +P1M,
// or -P1M for interoperability, be aware that other programs may not recognize it.
//
// The function returns a Duration structure or an error if the parsing fails.
func ParseDuration(b []byte) (Duration, error) {
var (
y int
Expand Down
27 changes: 15 additions & 12 deletions iso8601/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import (
"math"
)

/*
* Basic Extended
* 12 N/A
* 12.123456789 N/A
* 12,123456789 N/A
* 1230 12:30
* 1230.123456789 12:30.123456789
* 1230,123456789 12:30,123456789
* 123045 12:30:45
* 123045.123456789 12:30:45.123456789
* 123045,123456789 12:30:45,123456789
*/
// ParseTime attempts to parse a given byte slice representing a time in
// various supported ISO 8601 formats. Supported formats include:
//
// Basic Extended
// 12 N/A
// 12.123456789 N/A
// 12,123456789 N/A
// 1230 12:30
// 1230.123456789 12:30.123456789
// 1230,123456789 12:30,123456789
// 123045 12:30:45
// 123045.123456789 12:30:45.123456789
// 123045,123456789 12:30:45,123456789
//
// The function returns a Time structure or an error if the parsing fails.
func ParseTime(b []byte) (Time, error) {
n, t, err := parseTime(b)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions iso8601/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import (
"fmt"
)

// ParseZone attempts to parse a given byte slice representing a timezone offset
// in various supported ISO 8601 formats. Supported formats include:
//
// Basic Extended
// Z N/A
// ±hh N/A
// ±hhmm ±hh:mm
// ±hhmmss ±hh:mm:ss
//
// The function returns a Zone structure or an error if the parsing fails.
func ParseZone(b []byte) (Zone, error) {
if len(b) > 3 && b[3] == ':' {
return parseExtendedZone(b)
Expand Down

0 comments on commit 4cec26c

Please sign in to comment.