const Layout … const ANSIC … const UnixDate … const RubyDate … const RFC822 … const RFC822Z … const RFC850 … const RFC1123 … const RFC1123Z … const RFC3339 … const RFC3339Nano … const Kitchen … const Stamp … const StampMilli … const StampMicro … const StampNano … const DateTime … const DateOnly … const TimeOnly … const _ … const stdLongMonth … const stdMonth … const stdNumMonth … const stdZeroMonth … const stdLongWeekDay … const stdWeekDay … const stdDay … const stdUnderDay … const stdZeroDay … const stdUnderYearDay … const stdZeroYearDay … const stdHour … const stdHour12 … const stdZeroHour12 … const stdMinute … const stdZeroMinute … const stdSecond … const stdZeroSecond … const stdLongYear … const stdYear … const stdPM … const stdpm … const stdTZ … const stdISO8601TZ … const stdISO8601SecondsTZ … const stdISO8601ShortTZ … const stdISO8601ColonTZ … const stdISO8601ColonSecondsTZ … const stdNumTZ … const stdNumSecondsTz … const stdNumShortTZ … const stdNumColonTZ … const stdNumColonSecondsTZ … const stdFracSecond0 … const stdFracSecond9 … const stdNeedDate … const stdNeedYday … const stdNeedClock … const stdArgShift … const stdSeparatorShift … const stdMask … var std0x … // startsWithLowerCase reports whether the string has a lower-case letter at the beginning. // Its purpose is to prevent matching strings like "Month" when looking for "Mon". func startsWithLowerCase(str string) bool { … } // nextStdChunk finds the first occurrence of a std string in // layout and returns the text before, the std string, and the text after. // // nextStdChunk should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/searKing/golang/go // // Do not remove or change the type signature. // See go.dev/issue/67401. // //go:linkname nextStdChunk func nextStdChunk(layout string) (prefix string, std int, suffix string) { … } var longDayNames … var shortDayNames … var shortMonthNames … var longMonthNames … // match reports whether s1 and s2 match ignoring case. // It is assumed s1 and s2 are the same length. func match(s1, s2 string) bool { … } func lookup(tab []string, val string) (int, string, error) { … } // appendInt appends the decimal form of x to b and returns the result. // If the decimal form (excluding sign) is shorter than width, the result is padded with leading 0's. // Duplicates functionality in strconv, but avoids dependency. func appendInt(b []byte, x int, width int) []byte { … } var errAtoi … // Duplicates functionality in strconv, but avoids dependency. func atoi[bytes []byte | string](s bytes) (x int, err error) { … } // The "std" value passed to appendNano contains two packed fields: the number of // digits after the decimal and the separator character (period or comma). // These functions pack and unpack that variable. func stdFracSecond(code, n, c int) int { … } func digitsLen(std int) int { … } func separator(std int) byte { … } // appendNano appends a fractional second, as nanoseconds, to b // and returns the result. The nanosec must be within [0, 999999999]. func appendNano(b []byte, nanosec int, std int) []byte { … } // String returns the time formatted using the format string // // "2006-01-02 15:04:05.999999999 -0700 MST" // // If the time has a monotonic clock reading, the returned string // includes a final field "m=±<value>", where value is the monotonic // clock reading formatted as a decimal number of seconds. // // The returned string is meant for debugging; for a stable serialized // representation, use t.MarshalText, t.MarshalBinary, or t.Format // with an explicit format string. func (t Time) String() string { … } // GoString implements [fmt.GoStringer] and formats t to be printed in Go source // code. func (t Time) GoString() string { … } // Format returns a textual representation of the time value formatted according // to the layout defined by the argument. See the documentation for the // constant called [Layout] to see how to represent the layout format. // // The executable example for [Time.Format] demonstrates the working // of the layout string in detail and is a good reference. func (t Time) Format(layout string) string { … } // AppendFormat is like [Time.Format] but appends the textual // representation to b and returns the extended buffer. func (t Time) AppendFormat(b []byte, layout string) []byte { … } func (t Time) appendFormat(b []byte, layout string) []byte { … } var errBad … type ParseError … // newParseError creates a new ParseError. // The provided value and valueElem are cloned to avoid escaping their values. func newParseError(layout, value, layoutElem, valueElem, message string) *ParseError { … } const lowerhex … const runeSelf … const runeError … func quote(s string) string { … } // Error returns the string representation of a ParseError. func (e *ParseError) Error() string { … } // isDigit reports whether s[i] is in range and is a decimal digit. func isDigit[bytes []byte | string](s bytes, i int) bool { … } // getnum parses s[0:1] or s[0:2] (fixed forces s[0:2]) // as a decimal integer and returns the integer and the // remainder of the string. func getnum(s string, fixed bool) (int, string, error) { … } // getnum3 parses s[0:1], s[0:2], or s[0:3] (fixed forces s[0:3]) // as a decimal integer and returns the integer and the remainder // of the string. func getnum3(s string, fixed bool) (int, string, error) { … } func cutspace(s string) string { … } // skip removes the given prefix from value, // treating runs of space characters as equivalent. func skip(value, prefix string) (string, error) { … } // Parse parses a formatted string and returns the time value it represents. // See the documentation for the constant called [Layout] to see how to // represent the format. The second argument must be parseable using // the format string (layout) provided as the first argument. // // The example for [Time.Format] demonstrates the working of the layout string // in detail and is a good reference. // // When parsing (only), the input may contain a fractional second // field immediately after the seconds field, even if the layout does not // signify its presence. In that case either a comma or a decimal point // followed by a maximal series of digits is parsed as a fractional second. // Fractional seconds are truncated to nanosecond precision. // // Elements omitted from the layout are assumed to be zero or, when // zero is impossible, one, so parsing "3:04pm" returns the time // corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is // 0, this time is before the zero Time). // Years must be in the range 0000..9999. The day of the week is checked // for syntax but it is otherwise ignored. // // For layouts specifying the two-digit year 06, a value NN >= 69 will be treated // as 19NN and a value NN < 69 will be treated as 20NN. // // The remainder of this comment describes the handling of time zones. // // In the absence of a time zone indicator, Parse returns a time in UTC. // // When parsing a time with a zone offset like -0700, if the offset corresponds // to a time zone used by the current location ([Local]), then Parse uses that // location and zone in the returned time. Otherwise it records the time as // being in a fabricated location with time fixed at the given zone offset. // // When parsing a time with a zone abbreviation like MST, if the zone abbreviation // has a defined offset in the current location, then that offset is used. // The zone abbreviation "UTC" is recognized as UTC regardless of location. // If the zone abbreviation is unknown, Parse records the time as being // in a fabricated location with the given zone abbreviation and a zero offset. // This choice means that such a time can be parsed and reformatted with the // same layout losslessly, but the exact instant used in the representation will // differ by the actual zone offset. To avoid such problems, prefer time layouts // that use a numeric zone offset, or use [ParseInLocation]. func Parse(layout, value string) (Time, error) { … } // ParseInLocation is like Parse but differs in two important ways. // First, in the absence of time zone information, Parse interprets a time as UTC; // ParseInLocation interprets the time as in the given location. // Second, when given a zone offset or abbreviation, Parse tries to match it // against the Local location; ParseInLocation uses the given location. func ParseInLocation(layout, value string, loc *Location) (Time, error) { … } func parse(layout, value string, defaultLocation, local *Location) (Time, error) { … } // parseTimeZone parses a time zone string and returns its length. Time zones // are human-generated and unpredictable. We can't do precise error checking. // On the other hand, for a correct parse there must be a time zone at the // beginning of the string, so it's almost always true that there's one // there. We look at the beginning of the string for a run of upper-case letters. // If there are more than 5, it's an error. // If there are 4 or 5 and the last is a T, it's a time zone. // If there are 3, it's a time zone. // Otherwise, other than special cases, it's not a time zone. // GMT is special because it can have an hour offset. func parseTimeZone(value string) (length int, ok bool) { … } // parseGMT parses a GMT time zone. The input string is known to start "GMT". // The function checks whether that is followed by a sign and a number in the // range -23 through +23 excluding zero. func parseGMT(value string) int { … } // parseSignedOffset parses a signed timezone offset (e.g. "+03" or "-04"). // The function checks for a signed number in the range -23 through +23 excluding zero. // Returns length of the found offset string or 0 otherwise. func parseSignedOffset(value string) int { … } func commaOrPeriod(b byte) bool { … } func parseNanoseconds[bytes []byte | string](value bytes, nbytes int) (ns int, rangeErrString string, err error) { … } var errLeadingInt … // leadingInt consumes the leading [0-9]* from s. func leadingInt[bytes []byte | string](s bytes) (x uint64, rem bytes, err error) { … } // leadingFraction consumes the leading [0-9]* from s. // It is used only for fractions, so does not return an error on overflow, // it just stops accumulating precision. func leadingFraction(s string) (x uint64, scale float64, rem string) { … } var unitMap … // ParseDuration parses a duration string. // A duration string is a possibly signed sequence of // decimal numbers, each with optional fraction and a unit suffix, // such as "300ms", "-1.5h" or "2h45m". // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". func ParseDuration(s string) (Duration, error) { … }