Exemple #1
0
func GetGame(id string, t time.Time) (Game, error) {
	y, m, d := t.Date()

	url := fmt.Sprintf(GamedayBaseUrl+"/year_%d/month_%02d/day_%02d/epg.xml", y, m, d)

	resp, err := http.Get(url)

	if err != nil {
		return Game{}, err
	}

	var s Schedule

	err = Load(resp.Body, &s)

	if err != nil {
		return Game{}, err
	}

	for _, game := range s.Games {
		if game.HomeTeamId == id || game.AwayTeamId == id {
			return game, nil
		}
	}

	return Game{}, fmt.Errorf("Team %s doesn't have a game on %s", id, t)
}
Exemple #2
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}
}
Exemple #3
0
func (l *Logger) formatHeader(t time.Time) string {
	var s string

	//*buf = append(*buf, l.prefix...)
	if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
		if l.flag&Ldate != 0 {
			year, month, day := t.Date()
			s += itoa(year, 4)
			s += "/"
			s += itoa(int(month), 2)
			s += "/"
			s += itoa(day, 2)
		}
		if l.flag&(Ltime|Lmicroseconds) != 0 {
			hour, min, sec := t.Clock()

			s += " "
			s += itoa(hour, 2)
			s += ":"
			s += itoa(min, 2)
			s += ":"
			s += itoa(sec, 2)
			if l.flag&Lmicroseconds != 0 {
				s += "."
				s += itoa(t.Nanosecond()/1e3, 6)
			}
		}

		s += " "
	}
	return s
}
Exemple #4
0
func TDateMax(dt TDate, t time.Time) int {
	if dt == TDay {
		year, month, _ := t.Date()
		return DaysInMonth(int(month), year)
	}
	return td_limits[dt]
}
Exemple #5
0
func parseDateTime(str string, loc *time.Location) (time.Time, error) {
	var t time.Time
	var err error

	base := "0000-00-00 00:00:00.0000000"
	switch len(str) {
	case 10, 19, 21, 22, 23, 24, 25, 26:
		if str == base[:len(str)] {
			return t, err
		}
		t, err = time.Parse(timeFormat[:len(str)], str)
	default:
		err = ErrInvalidTimestring
		return t, err
	}

	// Adjust location
	if err == nil && loc != time.UTC {
		y, mo, d := t.Date()
		h, mi, s := t.Clock()
		t, err = time.Date(y, mo, d, h, mi, s, t.Nanosecond(), loc), nil
	}

	return t, err
}
Exemple #6
0
func formatHeader(flag int, t time.Time, file string, line int, funcname string) string {
	var buf bytes.Buffer
	buf.WriteByte('[')
	needspace := false
	if flag&(DateFlag|TimeFlag|MsecFlag) != 0 {
		if flag&DateFlag != 0 {
			year, month, day := t.Date()
			writespace(&buf, needspace)
			fmt.Fprintf(&buf, "%04d/%02d/%02d", year, month, day)
			needspace = true
		}
		if flag&(TimeFlag|MsecFlag) != 0 {
			hour, min, sec := t.Clock()
			writespace(&buf, needspace)
			fmt.Fprintf(&buf, "%02d:%02d:%02d", hour, min, sec)
			if flag&MsecFlag != 0 {
				fmt.Fprintf(&buf, ".%06d", t.Nanosecond()/1e3)
			}
			needspace = true
		}
	}
	if flag&(LongFileFlag|ShortFileFlag|FuncNameFlag) != 0 {
		if flag&ShortFileFlag != 0 {
			file = shortfilename(file)
		}
		writespace(&buf, needspace)
		fmt.Fprintf(&buf, "%s:%d", file, line)
		if flag&FuncNameFlag != 0 {
			fmt.Fprintf(&buf, " (%s)", shortfuncname(funcname))
		}
		needspace = true
	}
	buf.WriteByte(']')
	return buf.String()
}
Exemple #7
0
func (ø *TableForm) SetValues(row *pgsql.Row) {
	props := row.AsStrings()
	for k, v := range props {
		if !ø.HasFieldDefinition(k) {
			continue
		}
		elem := ø.FieldElement(k)
		if elem.Tag() == "select" {
			option := elem.Any(h.And_(h.Attr("value", v), h.Tag("option")))
			if option != nil {
				option.Add(h.Attr("selected", "selected"))
			}
		} else {
			if elem.Tag() == "textarea" {
				elem.Add(v)
			} else {
				//tp := elem.Attribute("type")
				//if tp == "date" {
				if elem.HasClass("date") {
					var tme time.Time
					field := row.Table.Field(k)
					row.Get(field, &tme)
					year, month, day := tme.Date()
					// %02.0f.%02.0f.%4.0f
					v = fmt.Sprintf("%4.0f-%02.0f-%02.0f", float64(year), float64(int(month)), float64(day))
				}
				elem.Add(h.Attr("value", v))
			}
		}
	}
}
Exemple #8
0
func showMonthCalendar(t time.Time) {
	year, month, _ := t.Date()

	fmt.Printf("\t\t%v\t\t%v\n", month, year)
	fmt.Println("Sun\tMon\tTue\tWed\tThu\tFri\tSat")

	cal := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
	end := cal.AddDate(0, 1, 0)
	if end.Weekday() != 0 {
		end = end.AddDate(0, 0, (int)(6-end.Weekday()))
	} else {
		end = end.AddDate(0, 0, -1)
	}

	cal = cal.AddDate(0, 0, (int)(-cal.Weekday()))

	for !end.Before(cal) {
		if cal.Weekday() == 6 {
			fmt.Println(cal.Day())
		} else {
			fmt.Print(cal.Day(), "\t")
		}
		cal = cal.AddDate(0, 0, 1)
	}
}
Exemple #9
0
func (source mondayAfternoons) GetBetween(start, end time.Time) ([]book.Booking, error) {

	// find next monday
	y, m, d := start.Date()
	daysUntilMonday := int((7 + time.Monday - start.Weekday()) % 7)
	nextmonday := time.Date(y, m, d+daysUntilMonday, 0, 0, 0, 0, start.Location())

	// build a map of booked dates
	bookedSet := make(map[time.Time]bool)
	if booked, err := source.session.List(); err != nil {
		return nil, err
	} else {
		for _, appointment := range booked {
			y, m, d = appointment.Timestamp.Date()
			date := time.Date(y, m, d, 0, 0, 0, 0, start.Location())
			bookedSet[date] = true
		}
	}

	// add a week at a time
	var bookings []book.Booking
	for !nextmonday.After(end) {
		// take days where nothing has been booked yet
		if _, exists := bookedSet[nextmonday]; !exists {
			bookings = append(bookings, lizafternoon{nextmonday})
		}
		nextmonday = nextmonday.AddDate(0, 0, 7)
	}
	return bookings, nil
}
Exemple #10
0
// TimeWithLocation returns a time.Time using the given location,
// while using the time values from the given time (day, hour, minutes, etc.)
func TimeWithLocation(l *time.Location, t time.Time) time.Time {
	y, m, d := t.Date()
	if l == nil {
		l = time.UTC
	}
	return time.Date(y, m, d, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), l)
}
Exemple #11
0
func checkDate(year int, month time.Month, day int, tm time.Time) bool {
	y, m, d := tm.Date()
	if y != year || m != month || d != day {
		return false
	}
	return true
}
Exemple #12
0
func ParseTime(str string, rel time.Time) time.Time {
	if t, ok := tryAll(str, rel, datetimeFormats); ok {
		return t
	}

	var dt, tt time.Time
	var dok, tok bool
	if strings.Index(str, " ") > -1 {
		parts := strings.SplitN(str, " ", 2)
		dt, dok = tryAll(parts[0], rel, dateFormats)
		tt, tok = tryAll(parts[1], rel, timeFormats)
	}
	if !dok || !tok {
		dt, dok = tryAll(str, rel, dateFormats)
		tt, tok = tryAll(str, rel, timeFormats)
	}
	if !dok && !tok {
		return time.Time{}
	}

	y, mo, d := dt.Date()
	if y == 0 {
		y, _, _ = rel.Date()
	}
	h, m, s := tt.Clock()
	return time.Date(y, mo, d, h, m, s, 0, rel.Location())
}
Exemple #13
0
func (w *Logger) logOneLine(asof time.Time, text, port string) {
	// figure out name of logfile based on UTC date, with daily rotation
	year, month, day := asof.Date()
	path := fmt.Sprintf("%s/%d", w.dir, year)
	err := os.MkdirAll(path, os.ModePerm)
	flow.Check(err)
	// e.g. "./logger/2014/20140122.txt"
	datePath := fmt.Sprintf("%s/%d.txt", path, (year*100+int(month))*100+day)

	if w.fd == nil || datePath != w.fd.Name() {
		if w.fd != nil {
			name := w.fd.Name()
			w.fd.Close()
			w.Out.Send(name) // report the closed file
		}
		mode := os.O_WRONLY | os.O_APPEND | os.O_CREATE
		fd, err := os.OpenFile(datePath, mode, os.ModePerm)
		flow.Check(err)
		w.fd = fd
	}
	// append a new log entry, here is an example of the format used:
	// 	L 01:02:03.537 usb-A40117UK OK 9 25 54 66 235 61 210 226 33 19
	hour, min, sec := asof.Clock()
	line := fmt.Sprintf("L %02d:%02d:%02d.%03d %s %s\n",
		hour, min, sec, jeebus.TimeToMs(asof)%1000, port, text)
	w.fd.WriteString(line)
}
Exemple #14
0
func (w *Writer) writeTime(v interface{}, t time.Time) (err error) {
	w.setRef(v)
	s := w.Stream
	year, month, day := t.Date()
	hour, min, sec := t.Clock()
	nsec := t.Nanosecond()
	tag := TagSemicolon
	if t.Location() == time.UTC {
		tag = TagUTC
	}
	if hour == 0 && min == 0 && sec == 0 && nsec == 0 {
		if _, err = s.Write(formatDate(year, int(month), day)); err == nil {
			err = s.WriteByte(tag)
		}
	} else if year == 1970 && month == 1 && day == 1 {
		if _, err = s.Write(formatTime(hour, min, sec, nsec)); err == nil {
			err = s.WriteByte(tag)
		}
	} else if _, err = s.Write(formatDate(year, int(month), day)); err == nil {
		if _, err = s.Write(formatTime(hour, min, sec, nsec)); err == nil {
			err = s.WriteByte(tag)
		}
	}
	return err
}
Exemple #15
0
func getTimeByRangeType(myTime *time.Time, rangeType dataRangeType) (beginTime time.Time, endTime time.Time) {
	h, m, s := myTime.Clock()
	y, M, d := myTime.Date()
	wd := myTime.Weekday()
	l := myTime.Location()
	var bh, bm, bs, eh, em, es = h, m, s, h, m, s
	var by, bM, bd, ey, eM, ed = y, M, d, y, M, d

	switch rangeType {
	case PerMinute:
		bh, bm, bs = h, m, 0
		eh, em, es = h, m, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerHour:
		bh, bm, bs = h, 0, 0
		eh, em, es = h, 59, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerDay:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerWeek:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, d-int(time.Sunday+wd)
		ey, eM, ed = y, M, d+int(time.Saturday-wd)
	case PerMonth:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, 1
		ey, eM, ed = y, M+1, 0
	case PerSeason:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		switch {
		case M >= time.January && M <= time.March:
			by, bM, bd = y, 1, 1
		case M >= time.April && M <= time.June:
			by, bM, bd = y, 4, 1
		case M >= time.July && M <= time.September:
			by, bM, bd = y, 7, 1
		case M >= time.October && M <= time.December:
			by, bM, bd = y, 10, 1
		}
		ey, eM, ed = y, bM+3, 0
	case PerYear:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, 1, 1
		ey, eM, ed = y, 12, 31
	}

	bt := time.Date(by, bM, bd, bh, bm, bs, 0, l)
	et := time.Date(ey, eM, ed, eh, em, es, 999999999, l)

	return bt, et
}
Exemple #16
0
func getDateString(d time.Time) string {
	if d.IsZero() {
		return "Date TBC"
	}

	year, month, day := d.Date()
	suffix := "th"
	switch day % 10 {
	case 1:
		if day%100 != 11 {
			suffix = "st"
		}
	case 2:
		if day%100 != 12 {
			suffix = "nd"
		}
	case 3:
		if day%100 != 13 {
			suffix = "rd"
		}
	}
	return d.Weekday().String() + " " + strconv.Itoa(day) + suffix + " " +
		month.String() + " " + strconv.Itoa(year)

}
Exemple #17
0
func appendTimeCommon(dst []byte, t time.Time) []byte {
	_, month, day := t.Date()

	dst = appendTwoDigits(dst, int(month))
	dst = appendTwoDigits(dst, day)

	hour, min, sec := t.Clock()

	dst = appendTwoDigits(dst, hour)
	dst = appendTwoDigits(dst, min)
	dst = appendTwoDigits(dst, sec)

	_, offset := t.Zone()

	switch {
	case offset/60 == 0:
		return append(dst, 'Z')
	case offset > 0:
		dst = append(dst, '+')
	case offset < 0:
		dst = append(dst, '-')
	}

	offsetMinutes := offset / 60
	if offsetMinutes < 0 {
		offsetMinutes = -offsetMinutes
	}

	dst = appendTwoDigits(dst, offsetMinutes/60)
	dst = appendTwoDigits(dst, offsetMinutes%60)

	return dst
}
Exemple #18
0
// rotateFile closes the syncBuffer's file and starts a new one.
func (sb *syncBuffer) rotateFile(now time.Time) error {
	if sb.file != nil {
		sb.Flush()
		sb.file.Close()
	}
	var err error
	sb.file, _, err = create(severityName[sb.sev], now)
	sb.nbytes = 0
	if err != nil {
		return err
	}

	sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)
	_, month, day := now.Date()
	sb.createdDate = fmt.Sprintf("%02d%02d", month, day)

	// Write header.
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "Log file created at: %s\n", now.Format("2006/01/02 15:04:05"))
	fmt.Fprintf(&buf, "Running on machine: %s\n", host)
	fmt.Fprintf(&buf, "Binary: Built with %s %s for %s/%s\n", runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH)
	fmt.Fprintf(&buf, "Log line format: [DIEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg\n")
	n, err := sb.file.Write(buf.Bytes())
	sb.nbytes += uint64(n)
	return err
}
Exemple #19
0
func CheckExpiration() error {
	return db.Update(func(tx *bolt.Tx) error {
		files := tx.Bucket([]byte("files"))
		filesCursor := files.Cursor()
		for fileToken, _ := filesCursor.First(); fileToken != nil; fileToken, _ = filesCursor.Next() {
			fileBucket := files.Bucket(fileToken)
			log.Println("Scanning file token", string(fileToken))

			possibleDeletionDate := time.Now()

			var deleteDate time.Time
			err := deleteDate.UnmarshalBinary(fileBucket.Get([]byte("delete-date")))
			if err != nil {
				log.Println("Delete date unmarshal error:", err)
				continue
			}
			d, m, y := possibleDeletionDate.Date()
			dd, mm, yy := deleteDate.Date()
			if d == dd && m == mm && y == yy {
				log.Println("Removing file...")
				err = os.RemoveAll(path.Join(uppath.UploadedPath, string(fileToken)))
				if err != nil {
					log.Println("Failed to remove file:", fileToken, " -", err)
					continue
				}
				files.DeleteBucket(fileToken)
			}
		}
		return nil
	})
}
Exemple #20
0
func (l *Logger) formatHeader(buf *bytes.Buffer, t time.Time, file string, line int, lvl int, reqId string, Func string) {
	if l.prefix != "" {
		buf.WriteString(l.prefix)
	}
	if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
		if l.flag&Ldate != 0 {
			year, month, day := t.Date()
			itoa(buf, year, 4)
			buf.WriteByte('/')
			itoa(buf, int(month), 2)
			buf.WriteByte('/')
			itoa(buf, day, 2)
			buf.WriteByte(' ')
		}
		if l.flag&(Ltime|Lmicroseconds) != 0 {
			hour, min, sec := t.Clock()
			itoa(buf, hour, 2)
			buf.WriteByte(':')
			itoa(buf, min, 2)
			buf.WriteByte(':')
			itoa(buf, sec, 2)
			if l.flag&Lmicroseconds != 0 {
				buf.WriteByte('.')
				itoa(buf, t.Nanosecond()/1e3, 6)
			}
			buf.WriteByte(' ')
		}
	}
	if reqId != "" {
		buf.WriteByte('[')
		buf.WriteString(reqId)
		buf.WriteByte(']')
	}
	if l.flag&Llevel != 0 {
		buf.WriteString(levels[lvl])
	}
	if l.flag&Lmodule != 0 {
		buf.WriteByte('[')
		buf.WriteString(Func)
		buf.WriteByte(']')

		buf.WriteByte(' ')
	}
	if l.flag&(Lshortfile|Llongfile) != 0 {
		if l.flag&Lshortfile != 0 {
			short := file
			for i := len(file) - 1; i > 0; i-- {
				if file[i] == '/' {
					short = file[i+1:]
					break
				}
			}
			file = short
		}
		buf.WriteString(file)
		buf.WriteByte(':')
		itoa(buf, line, -1)
		buf.WriteString(": ")
	}
}
Exemple #21
0
func globalLogFileUpdater() {
	init := true
	var now time.Time
	ticker := time.NewTicker(time.Duration(24 - time.Now().Hour()))
	for {
		if !init {
			now = <-ticker.C
			ticker.Stop()
			ticker = time.NewTicker(time.Hour * 24)
		} else {
			now = time.Now()
			roomLogChannel[0] = make(chan string, 18)
		}
		globalLogLock.Lock()
		globalLog.Close()
		year, month, day := now.Date()
		filename := fmt.Sprintf("room#0-%d-%s-%d", day,
			month.String(), year)

		globalLog, err := os.OpenFile(filename,
			os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
		if err != nil {
			helpers.Logger.Critical("%s", err.Error())
			continue
		}
		if !init {
			StopLogger(0)
		}
		globalLogLock.Unlock()
		go logListener(roomLogChannel[0], globalLog, 0)
		init = false
	}
}
Exemple #22
0
func formatTimeHeader(when time.Time) ([]byte, int) {
	y, mo, d := when.Date()
	h, mi, s := when.Clock()
	//len("2006/01/02 15:04:05 ")==20
	var buf [20]byte

	buf[0] = y1[y/1000%10]
	buf[1] = y2[y/100]
	buf[2] = y3[y-y/100*100]
	buf[3] = y4[y-y/100*100]
	buf[4] = '/'
	buf[5] = mo1[mo-1]
	buf[6] = mo2[mo-1]
	buf[7] = '/'
	buf[8] = d1[d-1]
	buf[9] = d2[d-1]
	buf[10] = ' '
	buf[11] = h1[h]
	buf[12] = h2[h]
	buf[13] = ':'
	buf[14] = mi1[mi]
	buf[15] = mi2[mi]
	buf[16] = ':'
	buf[17] = s1[s]
	buf[18] = s2[s]
	buf[19] = ' '

	return buf[0:], d
}
Exemple #23
0
// createFile creates log file with specified timestamp.
// l.mu held
func (l *Logger) createFile(t time.Time) error {
	year, month, day := t.Date()
	hour, min, sec := t.Clock()

	var file string
	switch l.options.Mode {
	case R_Size:
		file = fmt.Sprintf("%s-%04d%02d%02d-%02d%02d%02d", l.options.File, year, month, day, hour, min, sec)
	case R_Hour:
		file = fmt.Sprintf("%s-%04d%02d%02d-%02d", l.options.File, year, month, day, hour)
	case R_Day:
		file = fmt.Sprintf("%s-%04d%02d%02d", l.options.File, year, month, day)
	default: // R_None
		file = l.options.File
	}

	if l.file != nil {
		l.out.Flush()
		l.file.Close()
	}

	f, err := os.OpenFile(file, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
	if err != nil {
		return err
	}

	l.file = f
	l.out = bufio.NewWriterSize(f, bufferSize)
	l.nbytes = 0
	l.hour = hour
	l.day = day

	return nil
}
Exemple #24
0
func (log *Logger) date(now time.Time) {
	hour, minute, second := now.Clock()
	year, month, day := now.Date()
	//nsec := now.Nanosecond()
	itoa(&log.buf, year, 4)
	log.buf = append(log.buf, '-')
	itoa(&log.buf, int(month), 2)
	log.buf = append(log.buf, '-')
	itoa(&log.buf, day, 2)
	log.buf = append(log.buf, 'T')
	itoa(&log.buf, hour, 2)
	log.buf = append(log.buf, ':')
	itoa(&log.buf, minute, 2)
	log.buf = append(log.buf, ':')
	itoa(&log.buf, second, 2)
	//log.buf = append(log.buf, '.')
	//itoa(&log.buf, nsec, 9)
	_, off := now.Zone()
	if off == 0 {
		log.buf = append(log.buf, 'Z')
	} else {
		zone := off / 60
		absoff := off
		if zone < 0 {
			log.buf = append(log.buf, '-')
			absoff = -absoff
			zone = -zone
		} else {
			log.buf = append(log.buf, '+')
		}
		itoa(&log.buf, zone/60, 2)
		log.buf = append(log.buf, ':')
		itoa(&log.buf, zone%60, 2)
	}
}
Exemple #25
0
func (l *Logger) formatPrefix(level int, t time.Time, file string, line int) {
	// prefix: "D0806 10:45:19.598 bvc.go:100] "
	l.buf = append(l.buf, levelStr[level])

	_, month, day := t.Date()
	l.itoa(int(month), 2)
	l.itoa(day, 2)
	l.buf = append(l.buf, ' ')

	hour, min, sec := t.Clock()
	l.itoa(hour, 2)
	l.buf = append(l.buf, ':')
	l.itoa(min, 2)
	l.buf = append(l.buf, ':')
	l.itoa(sec, 2)
	l.buf = append(l.buf, '.')
	l.itoa(t.Nanosecond()/1e6, 3)
	l.buf = append(l.buf, ' ')

	short := file
	for i := len(file) - 1; i > 0; i-- {
		if file[i] == '/' {
			short = file[i+1:]
			break
		}
	}
	l.buf = append(l.buf, short...)
	l.buf = append(l.buf, ':')
	l.itoa(line, -1)
	l.buf = append(l.buf, "] "...)
}
Exemple #26
0
// Trasforma la variabile time passata in ingresso in una stringa ordinata e leggibile
func getTimeString(t time.Time) (date, clock string) {
	hour, min, sec := t.Clock()
	year, month, day := t.Date()
	clock = strings.Join([]string{strconv.Itoa(hour), strconv.Itoa(min), strconv.Itoa(sec)}, ".")
	date = strings.Join([]string{strconv.Itoa(day), month.String(), strconv.Itoa(year)}, "-")
	return
}
Exemple #27
0
func marshalTimeCommon(out *forkableWriter, t time.Time) (err error) {
	_, month, day := t.Date()

	err = marshalTwoDigits(out, int(month))
	if err != nil {
		return
	}

	err = marshalTwoDigits(out, day)
	if err != nil {
		return
	}

	hour, min, sec := t.Clock()

	err = marshalTwoDigits(out, hour)
	if err != nil {
		return
	}

	err = marshalTwoDigits(out, min)
	if err != nil {
		return
	}

	err = marshalTwoDigits(out, sec)
	if err != nil {
		return
	}

	_, offset := t.Zone()

	switch {
	case offset/60 == 0:
		err = out.WriteByte('Z')
		return
	case offset > 0:
		err = out.WriteByte('+')
	case offset < 0:
		err = out.WriteByte('-')
	}

	if err != nil {
		return
	}

	offsetMinutes := offset / 60
	if offsetMinutes < 0 {
		offsetMinutes = -offsetMinutes
	}

	err = marshalTwoDigits(out, offsetMinutes/60)
	if err != nil {
		return
	}

	err = marshalTwoDigits(out, offsetMinutes%60)
	return
}
Exemple #28
0
func (f FileSystem) MonthDirectory(date time.Time) string {
	year, month, _ := date.Date()
	monthDir := strings.ToLower(fmt.Sprintf("%d_%s", month, month.String()))
	yearDir := fmt.Sprintf("%d", year)
	path := path.Join(f.config.Root, yearDir, monthDir)
	f.bootstrap(path)
	return path
}
Exemple #29
0
func isSameDate(t1, t2 time.Time) bool {
	y1, m1, d1 := t1.Date()
	y2, m2, d2 := t2.Date()
	if y1 == y2 && m1 == m2 && d1 == d2 {
		return true
	}
	return false
}
Exemple #30
0
// Friendly date & time rendering
func friendlyTime(t time.Time) template.HTML {
	ty, tm, td := t.Date()
	ny, nm, nd := time.Now().Date()
	if (ty == ny) && (tm == nm) && (td == nd) {
		return template.HTML(t.Format("03:04:05 PM"))
	}
	return template.HTML(t.Format("Mon Jan 2, 2006"))
}