// writeSystemTZ writes system timezone info into mysql.tidb
347800
func writeSystemTZ(s Session) {
	sql := fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES ("%s", "%s", "TiDB Global System Timezone.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%s"`,
		mysql.SystemDB, mysql.TiDBTable, tidbSystemTZ, timeutil.InferSystemTZ(), timeutil.InferSystemTZ())
	mustExecute(s, sql)
}
1171193
func (t *tsmWriter) WriteIndex() error {
	indexPos := t.n

	if t.index.KeyCount() == 0 {
		return ErrNoValues
	}

	// Set the destination file on the index so we can periodically
	// fsync while writing the index.
	if f, ok := t.wrapped.(syncer); ok {
		t.index.(*directIndex).f = f
	}

	// Write the index
	if _, err := t.index.WriteTo(t.w); err != nil {
		return err
	}

	var buf [8]byte
	binary.BigEndian.PutUint64(buf[:], uint64(indexPos))

	// Write the index index position
	_, err := t.w.Write(buf[:])
	return err
}
78713
func init() {
	// We need set systemTZ when it is in testing process.
	if systemTZ == "" {
		systemTZ = "System"
	}
	locCa = &locCache{}
	locCa.locMap = make(map[string]*time.Location)
}
293194
func (db *DB) ZExpireAt(key []byte, when int64) (int64, error) {
	if when <= time.Now().Unix() {
		return 0, errExpireValue
	}

	return db.zExpireAt(key, when)
}
278538
func (m *Machine) AvailabilityZone() (string, error) {
	instData, err := getInstanceData(m.st, m.Id())
	if errors.IsNotFound(err) {
		return "", errors.Trace(errors.NotProvisionedf("machine %v", m.Id()))
	}
	if err != nil {
		return "", errors.Trace(err)
	}
	var zone string
	if instData.AvailZone != nil {
		zone = *instData.AvailZone
	}
	return zone, nil
}
170815
func FormatSQLTimestamp(t time.Time) string {
	_, zoneOffset := t.Zone()
	hasZone := zoneOffset != 0
	hasFracSecond := t.Nanosecond() != 0
	hasSecond := t.Second() != 0
	hasTime := t.Hour() != 0 || t.Minute() != 0
	hasDay := t.Day() != 1
	hasMonth := t.Month() != 1

	switch {
	case hasFracSecond:
		return t.Format(layoutNanosecond)
	case hasSecond:
		return t.Format(layoutSecond)
	case hasTime || hasZone:
		return t.Format(layoutMinute)
	case hasDay:
		return t.Format(layoutDay)
	case hasMonth:
		return t.Format(layoutMonth)
	default:
		return t.Format(layoutYear)
	}
}
1051856
func (f RangeFilter) TimeZone(timeZone string) RangeFilter {
	f.timeZone = timeZone
	return f
}
646355
func (v *Stats) WriteLatency() uint64 {
	if v.Writes == 0 {
		return 0
	}
	return (uint64)((v.WriteMs * 1000) / v.Writes)
}
354894
func (s *NumberValidateResponse) SetTimezone(v string) *NumberValidateResponse {
	s.Timezone = &v
	return s
}
471597
func (q *QueryStringQuery) TimeZone(timeZone string) *QueryStringQuery {
	q.timeZone = timeZone
	return q
}
381
func (s *GetMaintenanceWindowOutput) SetScheduleTimezone(v string) *GetMaintenanceWindowOutput {
	s.ScheduleTimezone = &v
	return s
}
954253
func (w *Writer) WriteTime(t *time.Time) {
	ptr := unsafe.Pointer(t)
	typ := reflect.TypeOf(t)
	if writeRef(w, ptr, typ) {
		return
	}
	setWriterRef(w, ptr, typ)
	year, month, day := t.Date()
	hour, min, sec := t.Clock()
	nsec := t.Nanosecond()
	buf := make([]byte, 9)
	if hour == 0 && min == 0 && sec == 0 && nsec == 0 {
		writeDate(w, buf, year, int(month), day)
	} else if year == 1970 && month == 1 && day == 1 {
		writeTime(w, buf, hour, min, sec, nsec)
	} else {
		writeDate(w, buf, year, int(month), day)
		writeTime(w, buf, hour, min, sec, nsec)
	}
	loc := TagSemicolon
	if t.Location() == time.UTC {
		loc = TagUTC
	}
	w.writeByte(loc)
}
397571
func (s *Server) heartbeatStatsz() {
	if s.sys.stmr != nil {
		s.sys.stmr.Reset(s.sys.statsz)
	}
	s.sendStatsz(fmt.Sprintf(serverStatsSubj, s.info.ID))
}
417630
func MakeTimestamptz(db XODB, v0 int, v1 int, v2 int, v3 int, v4 int, v5 float64, v6 int, v7 int, v8 int, v9 int, v10 int, v11 float64, v12 string) (time.Time, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.make_timestamptz($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`

	// run query
	var ret time.Time
	XOLog(sqlstr, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12).Scan(&ret)
	if err != nil {
		return time.Time{}, err
	}

	return ret, nil
}
1278407
func (t Term) Timezone(args ...interface{}) Term {
	return constructMethodTerm(t, "Timezone", p.Term_TIMEZONE, args, map[string]interface{}{})
}
1286588
func (v *NowValuer) Zone() *time.Location {
	if v.Location != nil {
		return v.Location
	}
	return nil
}
537648
func (a *AzureMonitor) Write(metrics []telegraf.Metric) error {
	azmetrics := make(map[uint64]*azureMonitorMetric, len(metrics))
	for _, m := range metrics {
		id := hashIDWithTagKeysOnly(m)
		if azm, ok := azmetrics[id]; !ok {
			amm, err := translate(m, a.NamespacePrefix)
			if err != nil {
				log.Printf("E! [outputs.azure_monitor]: could not create azure metric for %q; discarding point", m.Name())
				continue
			}
			azmetrics[id] = amm
		} else {
			amm, err := translate(m, a.NamespacePrefix)
			if err != nil {
				log.Printf("E! [outputs.azure_monitor]: could not create azure metric for %q; discarding point", m.Name())
				continue
			}

			azmetrics[id].Data.BaseData.Series = append(
				azm.Data.BaseData.Series,
				amm.Data.BaseData.Series...,
			)
		}
	}

	if len(azmetrics) == 0 {
		return nil
	}

	var body []byte
	for _, m := range azmetrics {
		// Azure Monitor accepts new batches of points in new-line delimited
		// JSON, following RFC 4288 (see https://github.com/ndjson/ndjson-spec).
		jsonBytes, err := json.Marshal(&m)
		if err != nil {
			return err
		}
		// Azure Monitor's maximum request body size of 4MB. Send batches that
		// exceed this size via separate write requests.
		if (len(body) + len(jsonBytes) + 1) > maxRequestBodySize {
			err := a.send(body)
			if err != nil {
				return err
			}
			body = nil
		}
		body = append(body, jsonBytes...)
		body = append(body, '\n')
	}

	return a.send(body)
}