// TimestampParse - parses the string and returns a Timestamp, or error
//
326618
func TimestampParse(s string) (Timestamp, error) {
	layout := "2006-01-02T15:04:05.999Z"
	t, e := time.Parse(layout, s)
	if e != nil {
		if strings.HasSuffix(s, "+00:00") || strings.HasSuffix(s, "-00:00") {
			t, e = time.Parse(layout, s[:len(s)-6]+"Z")
		} else if strings.HasSuffix(s, "+0000") || strings.HasSuffix(s, "-0000") {
			t, e = time.Parse(layout, s[:len(s)-5]+"Z")
		}
		if e != nil {
			var ts Timestamp
			return ts, e
		}
	}
	return Timestamp{t}, nil
}
434151
func Convert_Slice_string_To_v1_Time(input *[]string, out *Time, s conversion.Scope) error {
	str := ""
	if len(*input) > 0 {
		str = (*input)[0]
	}
	return out.UnmarshalQueryParameter(str)
}
696401
func FullTimeParse(value string) (time.Time, error) {
	layouts := []string{
		"2006-01-02T15:04:05.999999999Z0700",
		"2006-01-02T15:04:05.999999999Z07:00",
		"2006-01-02T15:04:05.999999999Z07",
	}
	var (
		err error
		t   time.Time
	)
	for _, layout := range layouts {
		if t, err = time.Parse(layout, value); err == nil {
			return t, nil
		}
	}
	return t, err
}
1012667
func NewTimestampOracle(cfg *Config) (*TimestampOracle, error) {
	if cfg.SaveInterval <= 0 {
		cfg.SaveInterval = defaultSaveInterval
	}

	tso := &TimestampOracle{
		cfg:      cfg,
		isLeader: 0,
	}

	var err error
	tso.listener, err = net.Listen("tcp", cfg.Addr)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if len(cfg.ZKAddr) == 0 {
		// no zookeeper, use a fake zk conn instead
		tso.zkConn = zkhelper.NewConn()
	} else {
		tso.zkConn, err = zkhelper.ConnectToZkWithTimeout(cfg.ZKAddr, zkTimeout)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}

	tso.conns = map[net.Conn]struct{}{}

	return tso, nil
}
1135748
func ParseTime(layout string, timeStr string) time.Time {
	res, err := time.Parse(layout, timeStr)
	if err != nil {
		panic(err)
	}
	return res
}
374177
func (c *ChatUpdateCall) Timestamp(timestamp string) *ChatUpdateCall {
	c.timestamp = timestamp
	return c
}
1344856
func timeString(t time.Time, c *color.Color) string {
	return c.SprintfFunc()(t.Format("2006-01-02 15:04 MST"))
}
774340
func TimestampToTime(timestamp *timestamp.Timestamp) time.Time {
	if timestamp == nil {
		return time.Unix(0, 0).UTC()
	}
	return time.Unix(
		timestamp.Seconds,
		int64(timestamp.Nanos),
	).UTC()
}
941032
func (qri *QueryRespItem) getSortedTimestampStrs() []string {
	timestampStrs := make([]string, 0)
	for timestampStr := range qri.Dps {
		timestampStrs = append(timestampStrs, timestampStr)
	}
	sort.Strings(timestampStrs)
	return timestampStrs
}
932909
func Parse(timeStr string) (time.Time, error) {
	err := errors.New("provided string is not W3C-DTF format")

	if !strings.Contains(timeStr, "T") {
		switch true {
		case IsYear(timeStr):
			return ParseYear(timeStr)
		case IsYearAndMonth(timeStr):
			return ParseYearAndMonth(timeStr)
		case IsCompleteDate(timeStr):
			return ParseCompleteDate(timeStr)
		default:
			return time.Time{}, err
		}
	} else {
		switch true {
		case IsCompleteDateWithMinutes(timeStr):
			return ParseCompleteDateWithMinutes(timeStr)
		case IsCompleteDateWithSeconds(timeStr):
			return ParseCompleteDateWithSeconds(timeStr)
		case IsCompleteDateWithFractionOfSecond(timeStr):
			return ParseCompleteDateWithFractionOfSecond(timeStr)
		default:
			return time.Time{}, err
		}
	}
}
461104
func (pt *ParseTime) Parse(value string) (time.Time, error) {
	times := make(sortedTimes, 0)
	t, priority, _ := parseISO8601(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseRFC8xx1123(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseANSIC(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseUS(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	if len(times) == 0 {
		var tmpT time.Time
		return tmpT, errInvalidDateTime
	}

	sort.Sort(times)

	return times[0].time, nil
}
669043
func TimeRepr(t time.Time) (string, error) {
	notification := TimeNotification{
		Time: t.String(),
	}
	repr, err := json.Marshal(notification)
	return string(repr), err
}
741923
func (m *Time) ProtoTime() *Timestamp {
	if m == nil {
		return &Timestamp{}
	}
	return &Timestamp{
		Seconds: m.Time.Unix(),
		// leaving this here for the record.  our JSON only handled seconds, so this results in writes by
		// protobuf clients storing values that aren't read by json clients, which results in unexpected
		// field mutation, which fails various validation and equality code.
		// Nanos:   int32(m.Time.Nanosecond()),
	}
}
1349574
func (u UUID) Timestamp() int64 {
	if u.Version() != 1 {
		return 0
	}
	return int64(uint64(u[0])<<24|uint64(u[1])<<16|
		uint64(u[2])<<8|uint64(u[3])) +
		int64(uint64(u[4])<<40|uint64(u[5])<<32) +
		int64(uint64(u[6]&0x0F)<<56|uint64(u[7])<<48)
}
158639
func StringToTime(s string) (t time.Time, e error) {
	for _, dateType := range layouts {
		if t, e = time.Parse(dateType, s); e == nil {
			return
		}
	}
	return t, fmt.Errorf("unable to parse date: %s", s)
}
855796
func (m *Time) ProtoTime() *ProtoTime {
	if m == nil {
		return &ProtoTime{}
	}
	return &ProtoTime{
		Timestamp: Timestamp{
			Seconds: m.Time.Unix(),
			Nanos:   int32(m.Time.Nanosecond()),
		},
	}
}
693308
func timeStampOffset() uint32 {
	b := make([]byte, 4)
	if _, err := rand.Read(b); err != nil {
		panic(err)
	}
	// Initialize a random tsOffset that will be added to the recentTS
	// everytime the timestamp is sent when the Timestamp option is enabled.
	//
	// See https://tools.ietf.org/html/rfc7323#section-5.4 for details on
	// why this is required.
	//
	// NOTE: This is not completely to spec as normally this should be
	// initialized in a manner analogous to how sequence numbers are
	// randomized per connection basis. But for now this is sufficient.
	return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
}