Golang Month示例

说明

golang month示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: Time

示例#1
文件: main.go 项目: nicolai86/traq

func main() {
	flag.Parse()

	var now = time.Now()
	if *month == -1 {
		*month = int(now.Month())
	}
	if *year == -1 {
		*year = now.Year()
	}

	r, err := leaveFile(*year)
	if err != nil {
		log.Fatal(err)
	}

	leave := &Leave{}
	json.NewDecoder(r).Decode(leave)

	startDate := time.Date(*year, time.Month(*month), 1, 0, 0, 0, 0, time.UTC)
	endDate := time.Date(*year, time.Month(*month+1), -1, 0, 0, 0, 0, time.UTC)

	expectedWorkTime := leave.expectedWorkTime(startDate, endDate)
	totalled := summarize(traq.TotalDate(*project, traq.ContentLoader, traq.DatesInMonth(*year, *month)...))

	fmt.Printf("work time for %4d-%02d: %2.2f vs %2.2f\n", *year, *month, float64(expectedWorkTime)/60.0/60.0, float64(totalled)/60.0/60.0)
}

示例#2
文件: cronexpr_next.go 项目: ZhuHangpeng/mig

func (expr *Expression) nextMonth(t time.Time) time.Time {
	// Find index at which item in list is greater or equal to
	// candidate month
	i := sort.SearchInts(expr.monthList, int(t.Month())+1)
	if i == len(expr.monthList) {
		return expr.nextYear(t)
	}
	// Month changed, need to recalculate actual days of month
	expr.actualDaysOfMonthList = expr.calculateActualDaysOfMonth(t.Year(), expr.monthList[i])
	if len(expr.actualDaysOfMonthList) == 0 {
		return expr.nextMonth(time.Date(
			t.Year(),
			time.Month(expr.monthList[i]),
			1,
			expr.hourList[0],
			expr.minuteList[0],
			expr.secondList[0],
			0,
			t.Location()))
	}

	return time.Date(
		t.Year(),
		time.Month(expr.monthList[i]),
		expr.actualDaysOfMonthList[0],
		expr.hourList[0],
		expr.minuteList[0],
		expr.secondList[0],
		0,
		t.Location())
}

示例#3
文件: line_test.go 项目: soniakeys/meeus

func ExampleTime() {
	// Example 19.a, p. 121.
	r1 := unit.AngleFromDeg(113.56833)
	d1 := unit.AngleFromDeg(31.89756)
	r2 := unit.AngleFromDeg(116.25042)
	d2 := unit.AngleFromDeg(28.03681)
	r3 := make([]unit.Angle, 5)
	for i, ri := range []float64{
		118.98067, 119.59396, 120.20413, 120.81108, 121.41475} {
		r3[i] = unit.AngleFromDeg(ri)
	}
	d3 := make([]unit.Angle, 5)
	for i, di := range []float64{
		21.68417, 21.58983, 21.49394, 21.39653, 21.29761} {
		d3[i] = unit.AngleFromDeg(di)
	}
	// use JD as time to handle month boundary
	jd, err := line.Time(r1, d1, r2, d2, r3, d3,
		julian.CalendarGregorianToJD(1994, 9, 29),
		julian.CalendarGregorianToJD(1994, 10, 3))
	if err != nil {
		fmt.Println(err)
		return
	}
	y, m, d := julian.JDToCalendar(jd)
	dInt, dFrac := math.Modf(d)
	fmt.Printf("%d %s %.4f\n", y, time.Month(m), d)
	fmt.Printf("%d %s %d, at %h TD(UT)\n", y, time.Month(m), int(dInt),
		sexa.FmtTime(unit.TimeFromDay(dFrac)))
	// Output:
	// 1994 October 1.2233
	// 1994 October 1, at 5ʰ TD(UT)
}

示例#4
文件: line_test.go 项目: thecc4re/meeus

func ExampleTime() {
	// Example 19.a, p. 121.

	// convert degree data to radians
	r1 := 113.56833 * math.Pi / 180
	d1 := 31.89756 * math.Pi / 180
	r2 := 116.25042 * math.Pi / 180
	d2 := 28.03681 * math.Pi / 180
	r3 := make([]float64, 5)
	for i, ri := range []float64{
		118.98067, 119.59396, 120.20413, 120.81108, 121.41475} {
		r3[i] = ri * math.Pi / 180
	}
	d3 := make([]float64, 5)
	for i, di := range []float64{
		21.68417, 21.58983, 21.49394, 21.39653, 21.29761} {
		d3[i] = di * math.Pi / 180
	}
	// use JD as time to handle month boundary
	jd, err := line.Time(r1, d1, r2, d2, r3, d3,
		julian.CalendarGregorianToJD(1994, 9, 29),
		julian.CalendarGregorianToJD(1994, 10, 3))
	if err != nil {
		fmt.Println(err)
		return
	}
	y, m, d := julian.JDToCalendar(jd)
	dInt, dFrac := math.Modf(d)
	fmt.Printf("%d %s %.4f\n", y, time.Month(m), d)
	fmt.Printf("%d %s %d, at %h TD(UT)\n", y, time.Month(m), int(dInt),
		sexa.NewFmtTime(dFrac*24*3600))
	// Output:
	// 1994 October 1.2233
	// 1994 October 1, at 5ʰ TD(UT)
}

示例#5
文件: dao_test.go 项目: xiongtoto0526/Scirpt

func TestTimezone(t *testing.T) {
	location, _ := time.LoadLocation("America/New_York")
	println(location.String())
	year := 2015
	month := 1
	day := 11
	hour := 13
	minute := 57

	localTime := time.Date(year, time.Month(month), day, hour, minute, 0, 0, location)
	//	utcTime := localTime.UTC()

	fmt.Println("localtime:", localTime)

	//	var t0=time.Now()
	//offset = 秒
	zoneName, offset := localTime.Local().Zone()
	println("zone name is:%s,offset is:%d", zoneName, offset)
	newtime := localTime.Add(time.Duration(offset * 1000000000))
	fmt.Println("newtime:", newtime)

	startDay, _ := time.Parse("2006-01-02", "2015-02-12")
	localTime = time.Date(2015, time.Month(2), 12, 0, 0, 0, 0, time.Local)

	fmt.Println("xht:", startDay.Local())
	fmt.Println("xht1:", localTime)

	t1 := time.Now()
	fmt.Println("diff is:", t1)
	year, month, day = convert2ymd("2015-09-28")
	println("xht2:", year, month, day)
}

示例#6
文件: more_test.go 项目: tianlin/go-oci8

func TestTime2(t *testing.T) {
	fmt.Println("test time 2:")

	const f = "2006-01-02 15:04:05.999999999 -07:00"
	in := []time.Time{}

	tm, err := time.Parse(f, "2015-01-23 12:34:56.123456789 +09:05")
	if err != nil {
		t.Fatal(err)
	}
	in = append(in, tm)

	tm, err = time.Parse(f, "1014-10-14 21:43:50.987654321 -08:50")
	if err != nil {
		t.Fatal(err)
	}
	in = append(in, tm)

	tm = time.Date(-4123, time.Month(12), 1, 2, 3, 4, 0, time.UTC)
	in = append(in, tm)

	tm = time.Date(9321, time.Month(11), 2, 3, 4, 5, 0, time.UTC)
	in = append(in, tm)

	r := sqlstestv(DB(), t, "select :0, :1, :2, :3  from dual", in[0], in[1], in[2], in[3])
	for i, v := range r {
		vt := v.(time.Time)
		if !vt.Equal(in[i]) {
			t.Fatal(vt, "!=", in[i])
		}
	}
}

示例#7
文件: main.go 项目: xyproto/moskus

func main() {
	cal, err := calendar.NewCalendar("en_US", true)
	if err != nil {
		panic("Could not create a US calendar!")
	}

	//year := time.Now().Year()
	year := 2016

	// When is easter this year?
	easter := calendar.EasterDay(year)
	fmt.Printf("Easter %d is at %s\n", year, easter.String()[:10])

	// Show some info for March this year
	//datebonanza(year, time.Month(3))

	// Show some info for March 2000
	//datebonanza(2000, time.Month(3))

	// Show some info for the current month
	datebonanza(cal, year, time.Month(time.Now().Month()))

	notable(cal, year)
	notable(cal, year+1)

	flag(cal, year)

	fmt.Println(cal.DayName(1))
	fmt.Println(cal.MonthName(time.Month(12)))
}

示例#8
文件: month.go 项目: bentranter/startupweekend2016

// DaysInMonth returns an array of all the days in the given month in the given
// year. Designed for use with html/template's `range` utility.
func DaysInMonth(y int, m Month) []time.Time {
	r := []time.Time{time.Date(y, time.Month(m), 1, 0, 0, 0, 0, time.UTC)}
	for i := 2; i <= m.lastDay(uint16(y)); i++ {
		r = append(r, time.Date(y, time.Month(m), i, 0, 0, 0, 0, time.UTC))
	}

	return r
}

示例#9
文件: calendar.go 项目: jouyouyun/lunarcalendar

/**
 * 计算两个公历日期之间的天数
 */
func getDaysBetweenSolar(year, month, day, year1, month1, day1 int32) (int64, bool) {
	date := time.Date(int(year), time.Month(month), int(day),
		0, 0, 0, 0, time.UTC).Unix()
	date1 := time.Date(int(year1), time.Month(month1), int(day1),
		0, 0, 0, 0, time.UTC).Unix()

	return (date1 - date) / 86400, true
}

示例#10
文件: z_interval_session_test.go 项目: optimuse/ora

func TestBindDefine_OraIntervalDS_ShiftTime_session(t *testing.T) {
	interval := ora.IntervalDS{Day: 1, Hour: 1, Minute: 1, Second: 1, Nanosecond: 123456789}
	actual := interval.ShiftTime(time.Date(2000, time.Month(1), 1, 0, 0, 0, 0, time.Local))
	expected := time.Date(2000, time.Month(1), 2, 1, 1, 1, 123456789, time.Local)
	if !expected.Equal(actual) {
		t.Fatalf("expected(%v), actual(%v)", expected, actual)
	}
}

示例#11
文件: portopt_test.go 项目: yasushi-saito/portopt

func TestDateRange(t *testing.T) {
	d := NewDateRange(
		time.Date(1980, time.Month(1), 1, 0, 0, 0, 0, time.UTC),
		time.Date(1980, time.Month(12), 31, 0, 0, 0, 0, time.UTC),
		time.Duration(time.Hour*24*30))

	for i := d.Begin(); !i.Done(); i.Next() {
		log.Print("ITER: ", i.Time())
	}
}

示例#12
文件: parse.go 项目: shenwei356/goftp

func getMonth(buf string) (m time.Month) {
	if len(buf) == 3 {
		for i := 0; i < 12; i++ {
			if strings.ToLower(buf) == MONTHS[i] {
				return time.Month(i + 1)
			}
		}
	}
	return time.Month(-1)
}

示例#13
文件: time.go 项目: hkjn/timeutils

// Parse extracts time from string-based info, with some constraints.
//
// The described time cannot be in the future, or more than 1000 years in the past.
//
// Note that month is 0-indexed, unlike time.Month.
func Parse(year, month, day, hourMinute string, loc *time.Location) (time.Time, error) {
	now := time.Now().In(loc)

	y64, err := strconv.ParseInt(year, 10, 0)
	y := int(y64)
	if err != nil {
		return time.Time{}, err
	}
	if y < now.Year()-1000 {
		return time.Time{}, fmt.Errorf("bad year; %d is too far in the past", y)
	}
	m, err := strconv.ParseInt(month, 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if m < 0 || m > 11 {
		return time.Time{}, fmt.Errorf("bad month: %d is not within [0, 11]", m)
	}
	// Month +1 since time.Month is [1, 12].
	m = m + 1
	d64, err := strconv.ParseInt(day, 10, 0)
	d := int(d64)
	if err != nil {
		return time.Time{}, err
	}
	if d < 1 {
		return time.Time{}, fmt.Errorf("bad day: %d; can't be negative", d)
	} else if d > daysIn(time.Month(m), y) {
		return time.Time{}, fmt.Errorf("bad day: %d; only %d days in %v, %d", d, daysIn(time.Month(m), y), time.Month(m), y)
	}
	parts := strings.Split(hourMinute, ":")
	if len(parts) != 2 {
		return time.Time{}, fmt.Errorf("bad hour/minute: %s", hourMinute)
	}
	h, err := strconv.ParseInt(parts[0], 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if h < 0 || h > 60 {
		return time.Time{}, fmt.Errorf("bad hour: %d", h)
	}
	min, err := strconv.ParseInt(parts[1], 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if min < 0 || min > 60 {
		return time.Time{}, fmt.Errorf("bad minute: %d", min)
	}

	t := time.Time(time.Date(int(y), time.Month(m), int(d), int(h), int(min), 0, 0, loc))
	if t.After(now) {
		return time.Time{}, fmt.Errorf("bad time; %v is in the future", time.Time(t))
	}
	return t, nil
}

示例#14
文件: time_series_test.go 项目: datacratic/gotsvis

func TestTimeSeriesExtend(t *testing.T) {
	start := time.Date(2016, time.Month(1), 25, 10, 0, 0, 0, time.UTC)
	step := time.Minute

	ts0, err := NewTimeSeriesOfData("test0", start, step, []float64{1, 2, 3})
	checkErr(t, err)
	ts1 := ts0.Copy()
	ts1.ExtendBy(3 * time.Minute)

	ts2 := ts0.Copy()
	ts2.ExtendTo(time.Date(2016, time.Month(1), 25, 10, 5, 0, 0, time.UTC))

	ts3 := ts0.Copy()
	ts3.ExtendWith([]float64{4, 5, 6})

	tss := []struct {
		Got *TimeSeries
		Exp *TimeSeries
	}{
		{
			Got: ts1,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, NaN, NaN, NaN},
			},
		},
		{
			Got: ts2,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, NaN, NaN, NaN},
			},
		},
		{
			Got: ts3,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, 4, 5, 6},
			},
		},
	}

	for _, pair := range tss {
		fmt.Printf("%s\n%s\n\n", pair.Got, pair.Exp)
		checkTimeSeries(t, pair.Got, pair.Exp)
	}
}

示例#15
文件: crontime_test.go 项目: Horrendus/beehive

func Test_calculateEventD(t *testing.T) {
	ipstr := [6]string{"*", "*", "03", "*", "*", "*"}
	baseTime := time.Date(2014, time.Month(1), 1, 4, 0, 0, 0, time.Local)
	expectedTime := time.Date(2014, time.Month(1), 2, 3, 0, 0, 10000, time.Local)
	cr := ParseInput(ipstr)
	if cr.calculateEvent(baseTime) != expectedTime {
		fmt.Println(cr.calculatedTime, expectedTime)
		t.Error("crontime: calculateEvent failed, 4")
	} else {
		t.Log("crontime: calculateEvent passed")
	}
}

示例#16
文件: crontime_test.go 项目: Horrendus/beehive

func Test_calculateEventF(t *testing.T) {
	ipstr := [6]string{"00", "00", "00", "*", "29", "02"}
	baseTime := time.Date(2016, time.Month(3), 29, 0, 0, 0, 0, time.Local)
	expectedTime := time.Date(2020, time.Month(2), 29, 0, 0, 0, 10000, time.Local)
	cr := ParseInput(ipstr)
	if cr.calculateEvent(baseTime) != expectedTime {
		fmt.Println(cr.calculatedTime, expectedTime)
		t.Error("crontime: calculateEvent failed, 6")
	} else {
		t.Log("crontime: calculateEvent passed")
	}
}

示例#17
文件: model.go 项目: fxgcj/website

func GetMonthBlogs(year, month int) (blogs Blogs) {
	begin := time.Date(year, time.Month(month), 0, 0, 0, 0, 0, time.Local)
	end := time.Date(year, time.Month(month+1), 0, 0, 0, 0, 0, time.Local)
	err := mongo.DB().WithC(mongo.C_BLOGS, func(db *mgo.Collection) error {
		return db.Find(bson.M{"created": bson.M{"$gte": begin, "$lt": end}}).Sort("-created").All(&blogs)
	})
	if err != nil {
		log.Error("find month error, ", err)
		return
	}
	log.Debug("get month, ", blogs)
	return
}

示例#18
文件: lexer.go 项目: pzsz/sp0rkle

func (l *dateLexer) setMonth(m, n int, year ...int) {
	if DEBUG {
		fmt.Printf("Setting month to %d %s\n", n, time.Month(m))
	}
	if l.state(HAVE_MONTHS, true) {
		l.Error("Parsed two months")
		return
	}
	l.months = relMonths{time.Month(m), n, 0}
	if len(year) > 0 {
		l.months.year = year[0]
	}
}

示例#19
文件: month.go 项目: kenshiro-o/recurrence

func (self Month) nextAfter(t time.Time) (time.Time, error) {
	desiredMonth := int(self)
	tMonth := int(t.Month())

	if tMonth < desiredMonth {
		return time.Date(t.Year(), time.Month(desiredMonth), 1, 0, 0, 0, 0, time.UTC), nil
	}

	if tMonth > desiredMonth || (tMonth == desiredMonth && isLastDayInMonth(t)) {
		return time.Date(t.Year()+1, time.Month(desiredMonth), 1, 0, 0, 0, 0, time.UTC), nil
	}

	return t.AddDate(0, 0, 1), nil
}

示例#20
文件: column.go 项目: qida/godbc

func (c *BaseColumn) Value(buf []byte) (driver.Value, error) {
	var p unsafe.Pointer
	if len(buf) > 0 {
		p = unsafe.Pointer(&buf[0])
	}
	switch c.CType {
	case api.SQL_C_BIT:
		return buf[0] != 0, nil
	case api.SQL_C_LONG:
		return *((*int32)(p)), nil
	case api.SQL_C_SBIGINT:
		return *((*int64)(p)), nil
	case api.SQL_C_DOUBLE:
		return *((*float64)(p)), nil
	case api.SQL_C_CHAR:
		return buf, nil
	case api.SQL_C_WCHAR:
		if p == nil {
			return nil, nil
		}
		s := (*[1 << 20]uint16)(p)[:len(buf)/2]
		return utf16toutf8(s), nil
	case api.SQL_C_TYPE_TIMESTAMP:
		t := (*api.SQL_TIMESTAMP_STRUCT)(p)
		r := time.Date(int(t.Year), time.Month(t.Month), int(t.Day),
			int(t.Hour), int(t.Minute), int(t.Second), int(t.Fraction),
			time.Local)
		return r, nil
	case api.SQL_C_GUID:
		t := (*api.SQLGUID)(p)
		var p1, p2 string
		for _, d := range t.Data4[:2] {
			p1 += fmt.Sprintf("%02x", d)
		}
		for _, d := range t.Data4[2:] {
			p2 += fmt.Sprintf("%02x", d)
		}
		r := fmt.Sprintf("%08x-%04x-%04x-%s-%s",
			t.Data1, t.Data2, t.Data3, p1, p2)
		return r, nil
	case api.SQL_C_DATE:
		t := (*api.SQL_DATE_STRUCT)(p)
		r := time.Date(int(t.Year), time.Month(t.Month), int(t.Day),
			0, 0, 0, 0, time.Local)
		return r, nil
	case api.SQL_C_BINARY:
		return buf, nil
	}
	return nil, fmt.Errorf("unsupported column ctype %d", c.CType)
}

示例#21
文件: resolver.go 项目: ChristianKniep/swarmkit

func resolve_time(val string, v reflect.Value, event yaml_event_t) (string, error) {
	var parsedTime time.Time
	matches := ymd_regexp.FindStringSubmatch(val)
	if len(matches) > 0 {
		year, _ := strconv.Atoi(matches[1])
		month, _ := strconv.Atoi(matches[2])
		day, _ := strconv.Atoi(matches[3])
		parsedTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
	} else {
		matches = timestamp_regexp.FindStringSubmatch(val)
		if len(matches) == 0 {
			return "", fmt.Errorf("Invalid timestamp: '%s' at %s", val, event.start_mark)
		}

		year, _ := strconv.Atoi(matches[1])
		month, _ := strconv.Atoi(matches[2])
		day, _ := strconv.Atoi(matches[3])
		hour, _ := strconv.Atoi(matches[4])
		min, _ := strconv.Atoi(matches[5])
		sec, _ := strconv.Atoi(matches[6])

		nsec := 0
		if matches[7] != "" {
			millis, _ := strconv.Atoi(matches[7])
			nsec = int(time.Duration(millis) * time.Millisecond)
		}

		loc := time.UTC
		if matches[8] != "" {
			sign := matches[8][0]
			hr, _ := strconv.Atoi(matches[8][1:])
			min := 0
			if matches[9] != "" {
				min, _ = strconv.Atoi(matches[9])
			}

			zoneOffset := (hr*60 + min) * 60
			if sign == '-' {
				zoneOffset = -zoneOffset
			}

			loc = time.FixedZone("", zoneOffset)
		}
		parsedTime = time.Date(year, time.Month(month), day, hour, min, sec, nsec, loc)
	}

	v.Set(reflect.ValueOf(parsedTime))
	return "", nil
}

示例#22
文件: timeutil_test.go 项目: essentialkaos/ek

func (s *TimeUtilSuite) TestDateNames(c *C) {
	c.Assert(getShortWeekday(time.Sunday), Equals, "Sun")
	c.Assert(getShortWeekday(time.Monday), Equals, "Mon")
	c.Assert(getShortWeekday(time.Tuesday), Equals, "Tue")
	c.Assert(getShortWeekday(time.Wednesday), Equals, "Wed")
	c.Assert(getShortWeekday(time.Thursday), Equals, "Thu")
	c.Assert(getShortWeekday(time.Friday), Equals, "Fri")
	c.Assert(getShortWeekday(time.Saturday), Equals, "Sat")
	c.Assert(getShortWeekday(time.Weekday(7)), Equals, "")

	c.Assert(getLongWeekday(time.Sunday), Equals, "Sunday")
	c.Assert(getLongWeekday(time.Monday), Equals, "Monday")
	c.Assert(getLongWeekday(time.Tuesday), Equals, "Tuesday")
	c.Assert(getLongWeekday(time.Wednesday), Equals, "Wednesday")
	c.Assert(getLongWeekday(time.Thursday), Equals, "Thursday")
	c.Assert(getLongWeekday(time.Friday), Equals, "Friday")
	c.Assert(getLongWeekday(time.Saturday), Equals, "Saturday")
	c.Assert(getLongWeekday(time.Weekday(7)), Equals, "")

	c.Assert(getShortMonth(time.Month(0)), Equals, "")
	c.Assert(getShortMonth(time.January), Equals, "Jan")
	c.Assert(getShortMonth(time.February), Equals, "Feb")
	c.Assert(getShortMonth(time.March), Equals, "Mar")
	c.Assert(getShortMonth(time.April), Equals, "Apr")
	c.Assert(getShortMonth(time.May), Equals, "May")
	c.Assert(getShortMonth(time.June), Equals, "Jun")
	c.Assert(getShortMonth(time.July), Equals, "Jul")
	c.Assert(getShortMonth(time.August), Equals, "Aug")
	c.Assert(getShortMonth(time.September), Equals, "Sep")
	c.Assert(getShortMonth(time.October), Equals, "Oct")
	c.Assert(getShortMonth(time.November), Equals, "Nov")
	c.Assert(getShortMonth(time.December), Equals, "Dec")

	c.Assert(getLongMonth(time.Month(0)), Equals, "")
	c.Assert(getLongMonth(time.January), Equals, "January")
	c.Assert(getLongMonth(time.February), Equals, "February")
	c.Assert(getLongMonth(time.March), Equals, "March")
	c.Assert(getLongMonth(time.April), Equals, "April")
	c.Assert(getLongMonth(time.May), Equals, "May")
	c.Assert(getLongMonth(time.June), Equals, "June")
	c.Assert(getLongMonth(time.July), Equals, "July")
	c.Assert(getLongMonth(time.August), Equals, "August")
	c.Assert(getLongMonth(time.September), Equals, "September")
	c.Assert(getLongMonth(time.October), Equals, "October")
	c.Assert(getLongMonth(time.November), Equals, "November")
	c.Assert(getLongMonth(time.December), Equals, "December")

	c.Assert(getWeekdayNum(time.Unix(1448193600, 0)), Equals, 7)
}

示例#23
文件: slices.go 项目: fridaysedge/info344-class-code

func main() {
	var months [12]string

	for idx := 0; idx < 12; idx++ {
		months[idx] = time.Month(idx + 1).String()
	}
	fmt.Println(months[0:])

	var dynoMonths []string

	for idx := 0; idx < 12; idx++ {
		dynoMonths = append(dynoMonths, time.Month(idx+1).String())
	}
	fmt.Println(dynoMonths)
}

示例#24
文件: jm_test.go 项目: thecc4re/meeus

func ExampleJewishCalendar() {
	// Example 9.a, p. 73.
	A, mP, dP, mNY, dNY, months, days := jm.JewishCalendar(1990)
	fmt.Println("Jewish Year:", A)
	fmt.Println("Pesach:     ", time.Month(mP), dP)
	fmt.Println("New Year:   ", time.Month(mNY), dNY)
	fmt.Println("Months:     ", months)
	fmt.Println("Days:       ", days)
	// Output:
	// Jewish Year: 5750
	// Pesach:      April 10
	// New Year:    September 20
	// Months:      12
	// Days:        354
}

示例#25
文件: main.go 项目: shawnps/budget

func main() {
	flag.Parse()
	b, err := parseFile(fmt.Sprintf("%s/%s.txt", *dir, *month))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Total:", b.Total)
	fmt.Println("Remaining:", b.Remaining)
	mon := *month
	year, err := strconv.Atoi(mon[0:4])
	if err != nil {
		log.Fatal(err)
	}
	m, err := strconv.Atoi(mon[4:6])
	if err != nil {
		log.Fatal(err)
	}
	rpd := b.Remaining / float64(daysIn(time.Month(m), year)-time.Now().Day())
	fmt.Printf("Remaining/day: %.2f\n", rpd)
	top := map[string]float64{}
	for _, t := range b.Transactions {
		top[t.Name] += t.Cost
	}
	fmt.Println("Top costs:")
	pl := sortMapByValue(top)
	for _, p := range pl {
		fmt.Printf("\t%s: %.2f\n", p.Key, p.Value)
	}
}

示例#26
文件: dateedit.go 项目: kumakichi/walk

func (de *DateEdit) systemTimeToTime(st *win.SYSTEMTIME) time.Time {
	if st == nil || !de.hasStyleBits(win.DTS_SHOWNONE) && st.WYear == 1601 && st.WMonth == 1 && st.WDay == 1 {
		return time.Time{}
	}

	return time.Date(int(st.WYear), time.Month(st.WMonth), int(st.WDay), 0, 0, 0, 0, time.Local)
}

示例#27
文件: metadata_test.go 项目: imoapps/juju

func (s *metadataSuite) TestAsJSONBuffer(c *gc.C) {
	meta := backups.NewMetadata()
	meta.Origin = backups.Origin{
		Environment: "asdf-zxcv-qwe",
		Machine:     "0",
		Hostname:    "myhost",
		Version:     version.MustParse("1.21-alpha3"),
	}
	meta.Started = time.Date(2014, time.Month(9), 9, 11, 59, 34, 0, time.UTC)

	meta.SetID("20140909-115934.asdf-zxcv-qwe")
	err := meta.MarkComplete(10, "123af2cef")
	c.Assert(err, jc.ErrorIsNil)

	finished := meta.Started.Add(time.Minute)
	meta.Finished = &finished

	buf, err := meta.AsJSONBuffer()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(buf.(*bytes.Buffer).String(), gc.Equals, `{`+
		`"ID":"20140909-115934.asdf-zxcv-qwe",`+
		`"Checksum":"123af2cef",`+
		`"ChecksumFormat":"SHA-1, base64 encoded",`+
		`"Size":10,`+
		`"Stored":"0001-01-01T00:00:00Z",`+
		`"Started":"2014-09-09T11:59:34Z",`+
		`"Finished":"2014-09-09T12:00:34Z",`+
		`"Notes":"",`+
		`"Environment":"asdf-zxcv-qwe",`+
		`"Machine":"0",`+
		`"Hostname":"myhost",`+
		`"Version":"1.21-alpha3"`+
		`}`+"\n")
}

示例#28
文件: chatlogs.go 项目: gpittarelli/Helen

//date regex - MM-DD-YYYY
func timestamp(date string) (time.Time, error) {
	if !dateRegex.MatchString(date) {
		return time.Time{}, errors.New("timestamp: invalid date")
	}

	var t time.Time
	matches := dateRegex.FindStringSubmatch(date)

	month, err := strconv.Atoi(matches[1])
	if err != nil {
		return t, err
	}

	day, err := strconv.Atoi(matches[2])
	if err != nil {
		return t, err
	}

	year, err := strconv.Atoi(matches[3])
	if err != nil {
		return t, err
	}

	t = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)

	return t, nil
}

示例#29
文件: couch2csv.go 项目: dustin/web-thermometer

func parseTime(in string) (time.Time, error) {
	parts := strings.FieldsFunc(in, func(r rune) bool {
		return r == '/' || r == '-' || r == ':' || r == 'T' ||
			r == ' ' || r == '.'
	})

	if len(parts) < 6 {
		return time.Time{},
			fmt.Errorf("Incorrect number of fields: %#v", parts)
	}

	np := []int{}
	for _, p := range parts {
		x, err := strconv.Atoi(p)
		if err != nil {
			return time.Time{}, errors.New("Unparsable time")
		}
		np = append(np, x)
	}

	nsec := 0
	if len(np) > 6 {
		nsec = np[6] * 1000
	}

	return time.Date(np[0], time.Month(np[1]), np[2],
		np[3], np[4], np[5], nsec, time.Local), nil
}

示例#30
文件: andnyang.go 项目: GDG-Korea/AndnyangWeb

func getSuffixQueryWithDateQuery(dateQuery string) string {
	year, _ := strconv.Atoi(dateQuery[0:4])
	monthNumber, _ := strconv.Atoi(dateQuery[4:6])
	month := time.Month(monthNumber)
	day, _ := strconv.Atoi(dateQuery[6:])
	return getSuffixQuery(year, month, day)
}

展开阅读全文