package time
import
func ( Time) ( []byte, bool) []byte {
, , := .locabs()
, , := .days().date()
= appendInt(, , 4)
= append(, '-')
= appendInt(, int(), 2)
= append(, '-')
= appendInt(, , 2)
= append(, 'T')
, , := .clock()
= appendInt(, , 2)
= append(, ':')
= appendInt(, , 2)
= append(, ':')
= appendInt(, , 2)
if {
:= stdFracSecond(stdFracSecond9, 9, '.')
= appendNano(, .Nanosecond(), )
}
if == 0 {
return append(, 'Z')
}
:= / 60
if < 0 {
= append(, '-')
= -
} else {
= append(, '+')
}
= appendInt(, /60, 2)
= append(, ':')
= appendInt(, %60, 2)
return
}
func ( Time) ( []byte) ([]byte, error) {
:= len()
= .appendFormatRFC3339(, true)
:= func( []byte) byte { return 10*([0]-'0') + ([1] - '0') }
switch {
case [+len("9999")] != '-':
return , errors.New("year outside of range [0,9999]")
case [len()-1] != 'Z':
:= [len()-len("Z07:00")]
if ('0' <= && <= '9') || ([len()-len("07:00"):]) >= 24 {
return , errors.New("timezone hour outside of range [0,23]")
}
}
return , nil
}
func [ []byte | string]( , *Location) (Time, bool) {
:= true
:= func( , , int) ( int) {
for , := range []byte() {
if < '0' || '9' < {
= false
return
}
= *10 + int() - '0'
}
if < || < {
= false
return
}
return
}
if len() < len("2006-01-02T15:04:05") {
return Time{}, false
}
:= ([0:4], 0, 9999)
:= ([5:7], 1, 12)
:= ([8:10], 1, daysIn(Month(), ))
:= ([11:13], 0, 23)
:= ([14:16], 0, 59)
:= ([17:19], 0, 59)
if ! || !([4] == '-' && [7] == '-' && [10] == 'T' && [13] == ':' && [16] == ':') {
return Time{}, false
}
= [19:]
var int
if len() >= 2 && [0] == '.' && isDigit(, 1) {
:= 2
for ; < len() && isDigit(, ); ++ {
}
, _, _ = parseNanoseconds(, )
= [:]
}
:= Date(, Month(), , , , , , UTC)
if len() != 1 || [0] != 'Z' {
if len() != len("-07:00") {
return Time{}, false
}
:= ([1:3], 0, 23)
:= ([4:6], 0, 59)
if ! || !(([0] == '-' || [0] == '+') && [3] == ':') {
return Time{}, false
}
:= (*60 + ) * 60
if [0] == '-' {
*= -1
}
.addSec(-int64())
if , , , , := .lookup(.unixSec()); == {
.setLoc()
} else {
.setLoc(FixedZone("", ))
}
}
return , true
}
func ( []byte) (Time, error) {
, := parseRFC3339(, Local)
if ! {
, := Parse(RFC3339, string())
if != nil {
return Time{},
}
:= func( []byte) byte { return 10*([0]-'0') + ([1] - '0') }
switch {
case true:
return , nil
case [len("2006-01-02T")+1] == ':':
return Time{}, &ParseError{RFC3339, string(), "15", string([len("2006-01-02T"):][:1]), ""}
case [len("2006-01-02T15:04:05")] == ',':
return Time{}, &ParseError{RFC3339, string(), ".", ",", ""}
case [len()-1] != 'Z':
switch {
case ([len()-len("07:00"):]) >= 24:
return Time{}, &ParseError{RFC3339, string(), "Z07:00", string([len()-len("Z07:00"):]), ": timezone hour out of range"}
case ([len()-len("00"):]) >= 60:
return Time{}, &ParseError{RFC3339, string(), "Z07:00", string([len()-len("Z07:00"):]), ": timezone minute out of range"}
}
default:
return Time{}, &ParseError{RFC3339, string(), RFC3339, string(), ""}
}
}
return , nil
}