Example #1
0
func (de *DateEdit) timeToSystemTime(t time.Time) *win.SYSTEMTIME {
	if t.Year() < 1601 {
		if de.hasStyleBits(win.DTS_SHOWNONE) {
			return nil
		} else {
			return &win.SYSTEMTIME{
				WYear:  uint16(1601),
				WMonth: uint16(1),
				WDay:   uint16(1),
			}
		}
	}

	st := &win.SYSTEMTIME{
		WYear:  uint16(t.Year()),
		WMonth: uint16(t.Month()),
		WDay:   uint16(t.Day()),
	}

	if de.timeOfDayDisplayed() {
		st.WHour = uint16(t.Hour())
		st.WMinute = uint16(t.Minute())
		st.WSecond = uint16(t.Second())
	}

	return st
}
Example #2
0
// FmtTimeMedium returns the medium time representation of 't' for 'ar_SA'
func (ar *ar_SA) FmtTimeMedium(t time.Time) string {

	b := make([]byte, 0, 32)

	h := t.Hour()

	if h > 12 {
		h -= 12
	}

	b = strconv.AppendInt(b, int64(h), 10)
	b = append(b, ar.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, ar.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20}...)

	if t.Hour() < 12 {
		b = append(b, ar.periodsAbbreviated[0]...)
	} else {
		b = append(b, ar.periodsAbbreviated[1]...)
	}

	return string(b)
}
Example #3
0
// FmtTimeLong returns the long time representation of 't' for 'en_SC'
func (en *en_SC) FmtTimeLong(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, en.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, en.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20}...)

	tz, _ := t.Zone()
	b = append(b, tz...)

	return string(b)
}
Example #4
0
func TestDateTimeLocal(t *testing.T) {
	zone := "Asia/Tokyo"
	tempFilename := TempFilename()
	db, err := sql.Open("sqlite3", tempFilename+"?_loc="+zone)
	if err != nil {
		t.Fatal("Failed to open database:", err)
	}
	db.Exec("CREATE TABLE foo (dt datetime);")
	db.Exec("INSERT INTO foo VALUES('2015-03-05 15:16:17');")

	row := db.QueryRow("select * from foo")
	var d time.Time
	err = row.Scan(&d)
	if err != nil {
		t.Fatal("Failed to scan datetime:", err)
	}
	if d.Hour() == 15 || !strings.Contains(d.String(), "JST") {
		t.Fatal("Result should have timezone", d)
	}
	db.Close()

	db, err = sql.Open("sqlite3", tempFilename)
	if err != nil {
		t.Fatal("Failed to open database:", err)
	}

	row = db.QueryRow("select * from foo")
	err = row.Scan(&d)
	if err != nil {
		t.Fatal("Failed to scan datetime:", err)
	}
	if d.UTC().Hour() != 15 || !strings.Contains(d.String(), "UTC") {
		t.Fatalf("Result should not have timezone %v %v", zone, d.String())
	}

	_, err = db.Exec("DELETE FROM foo")
	if err != nil {
		t.Fatal("Failed to delete table:", err)
	}
	dt, err := time.Parse("2006/1/2 15/4/5 -0700 MST", "2015/3/5 15/16/17 +0900 JST")
	if err != nil {
		t.Fatal("Failed to parse datetime:", err)
	}
	db.Exec("INSERT INTO foo VALUES(?);", dt)

	db.Close()
	db, err = sql.Open("sqlite3", tempFilename+"?_loc="+zone)
	if err != nil {
		t.Fatal("Failed to open database:", err)
	}

	row = db.QueryRow("select * from foo")
	err = row.Scan(&d)
	if err != nil {
		t.Fatal("Failed to scan datetime:", err)
	}
	if d.Hour() != 15 || !strings.Contains(d.String(), "JST") {
		t.Fatalf("Result should have timezone %v %v", zone, d.String())
	}
}
Example #5
0
// FmtTimeShort returns the short time representation of 't' for 'ta_MY'
func (ta *ta_MY) FmtTimeShort(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 12 {
		b = append(b, ta.periodsAbbreviated[0]...)
	} else {
		b = append(b, ta.periodsAbbreviated[1]...)
	}

	b = append(b, []byte{0x20}...)

	h := t.Hour()

	if h > 12 {
		h -= 12
	}

	b = strconv.AppendInt(b, int64(h), 10)
	b = append(b, ta.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)

	return string(b)
}
Example #6
0
// FmtTimeShort returns the short time representation of 't' for 'dz_BT'
func (dz *dz_BT) FmtTimeShort(t time.Time) string {

	b := make([]byte, 0, 32)

	b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b, 0x20}...)

	h := t.Hour()

	if h > 12 {
		h -= 12
	}

	b = strconv.AppendInt(b, int64(h), 10)
	b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbd, 0xa2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x98, 0xe0, 0xbc, 0x8b, 0x20}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x20}...)

	if t.Hour() < 12 {
		b = append(b, dz.periodsAbbreviated[0]...)
	} else {
		b = append(b, dz.periodsAbbreviated[1]...)
	}

	return string(b)
}
Example #7
0
// FmtTimeLong returns the long time representation of 't' for 'sr_Cyrl_RS'
func (sr *sr_Cyrl_RS) FmtTimeLong(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0x2e}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x2e}...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20}...)

	tz, _ := t.Zone()
	b = append(b, tz...)

	return string(b)
}
Example #8
0
// FmtTimeFull returns the full time representation of 't' for 'fr_BE'
func (fr *fr_BE) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0x20, 0x68}...)
	b = append(b, []byte{0x20}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x20, 0x6d, 0x69, 0x6e}...)
	b = append(b, []byte{0x20}...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20, 0x73}...)
	b = append(b, []byte{0x20}...)

	tz, _ := t.Zone()

	if btz, ok := fr.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	return string(b)
}
Example #9
0
// FmtTimeMedium returns the medium time representation of 't' for 'zh_Hans_MO'
func (zh *zh_Hans_MO) FmtTimeMedium(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 12 {
		b = append(b, zh.periodsAbbreviated[0]...)
	} else {
		b = append(b, zh.periodsAbbreviated[1]...)
	}

	h := t.Hour()

	if h > 12 {
		h -= 12
	}

	b = strconv.AppendInt(b, int64(h), 10)
	b = append(b, zh.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, zh.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)

	return string(b)
}
Example #10
0
func (this *Rotator) switchFile(now time.Time) error {
	if this.rotationByTime != NoRotation {
		logFileName := this.baseFileName
		logFileName += "." + now.Format(GetTimeFormat(this.rotationByTime))
		// fmt.Println("next log-name will be", logFileName, ".")
		switch this.rotationByTime {
		default:
			break
		case MinutelyRotation:
			this.nextRotationTime = now.Add(time.Minute).Add(-time.Duration(now.Second()) * time.Second).Unix()
		case HourlyRotation:
			this.nextRotationTime = now.Add(time.Hour).Add(-time.Duration(now.Second()+now.Minute()*60) * time.Second).Unix()
		case DailyRotation:
			this.nextRotationTime = now.Add(24 * time.Hour).Add(-time.Duration(now.Hour()*3600+now.Minute()*60+now.Second()) * time.Second).Unix()
		}
		// fmt.Println("next rotation time-point will be", this.nextRotationTime, " vs now ", now.Unix(), ".")
		logFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
		if err == nil {
			this.currentFileName = logFileName
			this.internalFile = logFile
			this.createSymLink(logFileName)
			// fmt.Println("file swapped.")
		}
		return err
	}
	return nil
}
Example #11
0
func ParseTime(str string) (time.Time, error) {
	now := time.Now()
	t := time.Time{}
	var err error

	isShortTime := false
	for _, tfmt := range inputTimeFormats {
		t, err = time.ParseInLocation(tfmt, str, time.Local)
		if err == nil {
			if tfmt == "03:04 pm" || tfmt == "3:04 pm" || tfmt == "15:04" {
				isShortTime = true
			}
			break
		}
		// fmt.Printf("%s \n", tfmt)
	}

	// if no year or month or day was given fill those in with todays date
	if isShortTime {
		t = time.Date(now.Year(), now.Month(), now.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.Local)
	} else if t.Year() == 0 { // no year was specified
		t = time.Date(now.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.Local)
	}

	return t, err
}
Example #12
0
File: alu.go Project: a2n/alu
func EasyDate(d time.Time) string {
	twZone, err := time.LoadLocation("Asia/Taipei")
	if err != nil {
		log.Print(err.Error())
		return ""
	}

	now := time.Now().In(twZone)
	today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, twZone)
	this_year := time.Date(now.Year(), time.January, 1, 0, 0, 0, 0, twZone)
	yesterday := today.Add(-24 * time.Hour)
	twoDaysBefore := yesterday.Add(-24 * time.Hour)

	str := fmt.Sprintf("%02d:%02d:%02d", d.Hour(), d.Minute(), d.Second())
	if d.After(yesterday) && d.Before(today) {
		str = "昨天 " + str
	} else if d.After(twoDaysBefore) && d.Before(yesterday) {
		str = "前天 " + str
	} else if d.After(this_year) && d.Before(twoDaysBefore) {
		str = fmt.Sprintf("%d 月 %d 日 ", d.Month(), d.Day()) + str
	} else if d.Before(this_year) {
		str = fmt.Sprintf("%02d-%02d-%02d ", d.Year()-1911, d.Month(), d.Day()) + str
	}

	return str
}
Example #13
0
func main() {
	p := fmt.Println
	var t time.Time = time.Now()
	fmt.Println(t)
	fmt.Println(t.Format(time.RFC3339))
	fmt.Println(t.Format(time.RFC3339Nano))

	t1, e := time.Parse(
		time.RFC3339,
		"2012-11-01T22:08:41-04:00")
	p(t1)

	p(t.Format("3:04PM"))
	p(t.Format("Mon Jan _2 15:04:05 2006"))
	p(t.Format("2006-01-02T15:04:05.999999-07:00"))
	form := "3 04 PM"
	t2, e := time.Parse(form, "8 41 PM")
	p(t2)
	fmt.Printf("%d - %02d - %02d T %02d : %02d : %02d . %d -00:00\n",
		t.Year(), t.Month(), t.Day(),
		t.Hour(), t.Minute(), t.Second(), t.Nanosecond())
	ansic := "Mon Jan _2 15:04:05 2006"
	_, e = time.Parse(ansic, "8:41PM")
	p(e)
}
Example #14
0
// FmtTimeFull returns the full time representation of 't' for 'th_TH'
func (th *th_TH) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0xac, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0xb2, 0x20}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20, 0xe0, 0xb8, 0xa7, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)

	tz, _ := t.Zone()

	if btz, ok := th.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	return string(b)
}
Example #15
0
// FmtTimeShort returns the short time representation of 't' for 'as_IN'
func (as *as_IN) FmtTimeShort(t time.Time) string {

	b := make([]byte, 0, 32)

	h := t.Hour()

	if h > 12 {
		h -= 12
	}

	b = strconv.AppendInt(b, int64(h), 10)
	b = append(b, []byte{0x2e}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x2e, 0x20}...)

	if t.Hour() < 12 {
		b = append(b, as.periodsAbbreviated[0]...)
	} else {
		b = append(b, as.periodsAbbreviated[1]...)
	}

	return string(b)
}
Example #16
0
func Strftime(format string, t time.Time) (timestamp string, err error) {
	c_format := C.CString(format)
	defer func() { C.free(unsafe.Pointer(c_format)) }()

	tz, offset := t.Zone()
	c_tz := C.CString(tz)
	defer func() { C.free(unsafe.Pointer(c_tz)) }()

	c_time := C.struct_tm{
		tm_year:   C.int(t.Year() - 1900),
		tm_mon:    C.int(t.Month() - 1),
		tm_mday:   C.int(t.Day()),
		tm_hour:   C.int(t.Hour()),
		tm_min:    C.int(t.Minute()),
		tm_sec:    C.int(t.Second()),
		tm_gmtoff: C.long(offset),
		tm_zone:   c_tz,
	}

	c_timestamp, trr := C.ftime(c_format, &c_time)
	defer func() { C.free(unsafe.Pointer(c_timestamp)) }()

	timestamp = C.GoString(c_timestamp)
	if trr == nil {
		timestamp = C.GoString(c_timestamp)
	} else {
		err = fmt.Errorf("%s - %s", trr, t)
	}
	return
}
Example #17
0
func (de *DateEncoder) getTimeOfDayScaler(date time.Time) float64 {
	if de.timeOfDayEncoder == nil {
		return 0.0
	}
	return float64(date.Hour()) + (float64(date.Minute()) / 60.0)

}
Example #18
0
// FmtTimeLong returns the long time representation of 't' for 'uz_Latn_UZ'
func (uz *uz_Latn_UZ) FmtTimeLong(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, uz.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, uz.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20, 0x28}...)

	tz, _ := t.Zone()
	b = append(b, tz...)

	b = append(b, []byte{0x29}...)

	return string(b)
}
Example #19
0
func buildTimeElement(t time.Time) string {
	return fmt.Sprintf(
		"<dateTime.iso8601>%d%d%dT%d:%d:%d</dateTime.iso8601>",
		t.Year(), t.Month(), t.Day(),
		t.Hour(), t.Minute(), t.Second(),
	)
}
Example #20
0
// dateSize returns the size needed to store a given time.Time.
func dateSize(v time.Time) (length uint8) {
	var (
		month, day, hour, min, sec uint8
		year                       uint16
		msec                       uint32
	)

	year = uint16(v.Year())
	month = uint8(v.Month())
	day = uint8(v.Day())
	hour = uint8(v.Hour())
	min = uint8(v.Minute())
	sec = uint8(v.Second())
	msec = uint32(v.Nanosecond() / 1000)

	if hour == 0 && min == 0 && sec == 0 && msec == 0 {
		if year == 0 && month == 0 && day == 0 {
			return 0
		} else {
			length = 4
		}
	} else if msec == 0 {
		length = 7
	} else {
		length = 11
	}
	length++ // 1 extra byte needed to store the length itself
	return
}
Example #21
0
// FmtTimeFull returns the full time representation of 't' for 'eo'
func (eo *eo) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0x2d, 0x61}...)
	b = append(b, []byte{0x20, 0x68, 0x6f, 0x72, 0x6f}...)
	b = append(b, []byte{0x20, 0x6b, 0x61, 0x6a}...)
	b = append(b, []byte{0x20}...)
	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, eo.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20}...)

	tz, _ := t.Zone()

	if btz, ok := eo.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	return string(b)
}
Example #22
0
func (self *Tracker) TrackTime(accountStr, evtType string, now time.Time) {

	go func(key, evtType string, now time.Time) {

		defer func() {
			if err := recover(); err != nil {
				log.Println("Goroutine failed:", err)
			}
		}()

		yearAsString := strconv.Itoa(now.Year())
		monthAsString := strconv.Itoa(int(now.Month()))
		dayAsString := strconv.Itoa(now.Day())
		hourAsString := strconv.Itoa(now.Hour())

		// increment current month in year
		yearKey := fmt.Sprintf("track:%s:%s:%s", key, evtType, yearAsString)
		self.Conn.HIncrBy(yearKey, monthAsString, 1)

		// increment current day in month
		monthKey := fmt.Sprintf("track:%s:%s:%s:%s", key, evtType, yearAsString, monthAsString)
		self.Conn.HIncrBy(monthKey, dayAsString, 1)

		// increment current hour in day
		dayKey := fmt.Sprintf("track:%s:%s:%s:%s:%s", key, evtType, yearAsString, monthAsString, dayAsString)
		self.Conn.HIncrBy(dayKey, hourAsString, 1)

		// Expire day entry after a month
		// self.Conn.Expire(dayKey, 2592000)

	}(accountStr, evtType, now)
}
Example #23
0
// given a time, calculate the instant that the log should next roll
func calculateNextRollTime(t time.Time, freq rollFrequency) time.Time {
	if freq == RollMinutely {
		t = t.Truncate(time.Minute)
		t = t.Add(time.Minute)
	} else if freq == RollHourly {
		t = t.Truncate(time.Hour)
		t = t.Add(time.Hour)
	} else {
		t = t.Truncate(time.Hour)
		// easiest way to beat DST bugs is to just iterate
		for t.Hour() > 0 {
			t = t.Add(-time.Hour)
		}
		if freq == RollDaily {
			t = t.AddDate(0, 0, 1)
		} else {
			if t.Weekday() == time.Sunday {
				t = t.AddDate(0, 0, 7)
			} else {
				for t.Weekday() != time.Sunday {
					t = t.AddDate(0, 0, 1)
				}
			}
		}
	}

	return t
}
Example #24
0
// FmtTimeFull returns the full time representation of 't' for 'ja'
func (ja *ja) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0xe6, 0x99, 0x82}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0xe5, 0x88, 0x86}...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0xe7, 0xa7, 0x92, 0x20}...)

	tz, _ := t.Zone()

	if btz, ok := ja.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	return string(b)
}
Example #25
0
// FmtTimeMedium returns the medium time representation of 't' for 'be_BY'
func (be *be_BY) FmtTimeMedium(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, []byte{0x2e}...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, []byte{0x2e}...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)

	return string(b)
}
Example #26
0
// FmtTimeFull returns the full time representation of 't' for 'uz_Arab_AF'
func (uz *uz_Arab_AF) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, uz.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, uz.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20, 0x28}...)

	tz, _ := t.Zone()

	if btz, ok := uz.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	b = append(b, []byte{0x29}...)

	return string(b)
}
Example #27
0
// FmtTimeMedium returns the medium time representation of 't' for 'en_SC'
func (en *en_SC) FmtTimeMedium(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, en.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, en.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)

	return string(b)
}
Example #28
0
func isGametime(t time.Time) bool {
	var start, end time.Time
	year := t.Year()
	month := t.Month()
	day := t.Day()
	hour := t.Hour()
	loc := t.Location()
	switch t.Weekday() {
	case time.Monday, time.Tuesday, time.Wednesday, time.Thursday:
		start = time.Date(year, month, day, 20, 0, 0, 0, loc)
		end = time.Date(year, month, day, 23, 59, 59, 999999999, loc)
	case time.Friday:
		start = time.Date(year, month, day, 19, 0, 0, 0, loc)
		end = time.Date(year, month, day+1, 2, 59, 59, 999999999, loc)
	case time.Saturday:
		if hour < 3 {
			start = time.Date(year, month, day-1, 23, 59, 59, 999999999, loc)
			end = time.Date(year, month, day, 2, 59, 59, 999999999, loc)
		} else {
			start = time.Date(year, month, day, 15, 0, 0, 0, loc)
			end = time.Date(year, month, day+1, 2, 59, 59, 999999999, loc)
		}
	case time.Sunday:
		if hour < 3 {
			start = time.Date(year, month, day-1, 23, 59, 59, 999999999, loc)
			end = time.Date(year, month, day, 2, 59, 59, 999999999, loc)
		} else {
			start = time.Date(year, month, day, 17, 0, 0, 0, loc)
			end = time.Date(year, month, day, 23, 59, 59, 999999999, loc)
		}
	}
	return (t.After(start) && t.Before(end))
}
Example #29
0
// FmtTimeFull returns the full time representation of 't' for 'en_SC'
func (en *en_SC) FmtTimeFull(t time.Time) string {

	b := make([]byte, 0, 32)

	if t.Hour() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Hour()), 10)
	b = append(b, en.timeSeparator...)

	if t.Minute() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Minute()), 10)
	b = append(b, en.timeSeparator...)

	if t.Second() < 10 {
		b = append(b, '0')
	}

	b = strconv.AppendInt(b, int64(t.Second()), 10)
	b = append(b, []byte{0x20}...)

	tz, _ := t.Zone()

	if btz, ok := en.timezones[tz]; ok {
		b = append(b, btz...)
	} else {
		b = append(b, tz...)
	}

	return string(b)
}
Example #30
0
func newTime(now time.Time) *Time {
	year, _month, day := now.Date()
	month := int(_month)
	_, week := now.ISOWeek()
	hour := now.Hour()
	return &Time{year, month, day, hour, week}
}