當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Time.Month類代碼示例

本文整理匯總了Golang中Time.Month的典型用法代碼示例。如果您正苦於以下問題:Golang Month類的具體用法?Golang Month怎麽用?Golang Month使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Month類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewMonth

func NewMonth(n time.Month, y, p int) (m *month) {
	m = &month{year: y, number: n, payday: p}
	t := time.Date(y, n, 1, 0, 0, 0, 0, time.Local)

	for {
		m.days = append(m.days, t)
		t = time.Date(y, n, t.Day()+1, 0, 0, 0, 0, time.Local)

		if t.Month().String() != n.String() {
			break
		}
	}

	return
}
開發者ID:kentaro,項目名稱:hanakin,代碼行數:15,代碼來源:hanakin.go

示例2: printCal

func printCal(month time.Month, year int) {
	dayw := "Su Mo Tu We Th Fr Sa"

	s := month.String() + " " + strconv.FormatInt(int64(year), 10)

	off := (20 - len(s)) / 2

	for i := 0; i < off; i++ {
		s = " " + s
	}

	s += "\n" + dayw + "\n"

	mth := months(year)

	day := januaryFirst(year)

	for i := 1; i < int(month); i++ {
		day += mth[i-1]
	}

	for i := 0; i < day%7; i++ {
		s = s + "   "
	}

	for i := 1; i <= mth[month-1]; i++ {
		s = s + " "
		if i < 10 {
			s = s + " "
		}
		s = s + strconv.Itoa(i)
		day += 1
		if day%7 == 0 {
			s = s + "\n"
		}
	}

	s = s + "\n\n"

	fmt.Print(s)
}
開發者ID:guelfey,項目名稱:goblin-old,代碼行數:41,代碼來源:cal.go

示例3: datebonanza

// List all the days of a given month
func datebonanza(cal calendar.Calendar, year int, month time.Month) {
	fmt.Println(month.String(), year)
	fmt.Println("====================")

	current := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)

	// As long as we are in the same month
	for current.Month() == month {

		if red, desc, flag := cal.RedDay(current); red {
			fmt.Printf("%s is red: %s (flag: %v)\n", current.String()[:10], desc, flag)
		}

		if notable, desc, flag := cal.NotableDay(current); notable {
			fmt.Printf("%s is notable: %s (flag: %v)\n", current.String()[:10], desc, flag)
		}

		// Advance to the next day
		current = current.AddDate(0, 0, 1)
	}
	fmt.Println()
}
開發者ID:xyproto,項目名稱:moskus,代碼行數:23,代碼來源:main.go

示例4: buildMonth

func buildMonth(month time.Month, year int) *Month {
	log.Println("building month", month)
	n := time.Now().Local()
	m := Month{}
	m.Name = month.String()
	days := time.Date(year, month+1, 0, 0, 0, 0, 0, location).Day()
	start := time.Date(year, month, 1, 0, 0, 0, 0, location)
	m.StartPos = int(start.Weekday())
	for i := 1; i <= days; i++ {
		d := time.Date(year, month, i, 0, 0, 0, 0, location)
		day := Day{
			d,
			i,
			int(d.Weekday()),
			d.YearDay(),
			n.YearDay() > d.YearDay(),
			[]meetup.Event{},
		}
		m.Days = append(m.Days, &day)
	}
	return &m
}
開發者ID:GoMN,項目名稱:golang.mn,代碼行數:22,代碼來源:bootstrap.go

示例5: tvd

//Tss vs Duration
func tvd(user types.UserSettings, filter Filter) ([]Tvd, string) {
	user_id := user.Id
	tvd_data_points := make([]Tvd_data_point, 0)
	tvd_data := make([]Tvd, 0)
	var user_data types.Metrics
	var end_summary_json []byte
	var activity_start time.Time
	var tvdLegend string

	cluster := gocql.NewCluster(config.DbHost)
	cluster.Keyspace = "joulepersecond"
	cluster.Consistency = gocql.Quorum
	session, _ := cluster.CreateSession()
	defer session.Close()

	//get all of the user's data (at least all for now) TODO limit these queries by date if poss. Done!
	timeNow := time.Now()
	timeThen := timeNow.AddDate(0, 0, -filter.Historylen)
	iter := session.Query(`SELECT activity_start, end_summary_json FROM joulepersecond.user_activity WHERE user_id = ? AND activity_start > ? ORDER BY activity_start ASC`, user_id, timeThen).Iter()
	for iter.Scan(&activity_start, &end_summary_json) {
		var tvd_data_point Tvd_data_point
		json.Unmarshal(end_summary_json, &user_data)

		tvd_data_point.Date = user_data.StartTime
		tvd_data_point.Dur = user_data.Dur
		if user_data.Utss > 0 {
			tvd_data_point.Tss = user_data.Utss
		} else if user_data.Tss > 0 {
			tvd_data_point.Tss = user_data.Tss
		} else if user_data.Etss > 0 {
			tvd_data_point.Tss = user_data.Etss
		} else {
			tvd_data_point.Tss = 0
		}
		tvd_data_points = append(tvd_data_points, tvd_data_point)
	}

	//we now have all the data... Now sort it
	sumTss := 0
	var sumDur time.Duration
	var lastActivity time.Time
	//loope through each retrieved activity
	for i := 1; i < len(tvd_data_points); i++ {
		//set last activity on first iteration only
		if i == 1 {
			lastActivity = tvd_data_points[i].Date
		}
		//if we want to show data in monthly format
		if filter.Historylen > 366 { //show over 365 days as monthly
			thisDate := tvd_data_points[i].Date
			prevDate := lastActivity

			//if we're still in the current month sum these values
			if thisDate.Month() != prevDate.Month() || i == len(tvd_data_points)-1 {
				var summedMonthlyTvd Tvd
				summedMonthlyTvd.TotalTss = sumTss
				summedMonthlyTvd.TotalDur = utility.Round(sumDur.Hours(), .5, 2)

				var month time.Month
				var year string
				if thisDate.Month() != prevDate.Month() {
					month = prevDate.Month()
					year = strconv.Itoa(prevDate.Year())
				} else {
					month = thisDate.Month()
					year = strconv.Itoa(thisDate.Year())
				}

				monthStr := month.String()
				summedMonthlyTvd.TimeLabel = monthStr[0:3] + " '" + year[2:4]

				sumTss = 0
				sumDur = 0
				tvd_data = append(tvd_data, summedMonthlyTvd)

				//reset the last activity date for the next loop
				lastActivity = thisDate
			}

			sumTss += tvd_data_points[i].Tss
			sumDur += tvd_data_points[i].Dur

			tvdLegend = "By Month"
		} else {
			thisDate := tvd_data_points[i].Date //we use this to compare the activity being scanned with the last to see if it is in the same week
			prevDate := lastActivity            //this is the last activity that we scanned that was the first of the new week, last week. Confusing init? we have to get the value now, and change if the weeks are not equal (new week)
			prevIterDate := tvd_data_points[i-1].Date

			//get week number for this and last activity
			_, thisDateWeek := thisDate.ISOWeek()
			prevDateYear, prevDateWeek := prevDate.ISOWeek()

			if thisDateWeek != prevDateWeek || i == len(tvd_data_points)-1 {
				var summedWeeklyTvd Tvd
				summedWeeklyTvd.TotalTss = sumTss
				summedWeeklyTvd.TotalDur = utility.Round(sumDur.Hours(), .5, 2)

				monthS := prevDate.Month()

//.........這裏部分代碼省略.........
開發者ID:jezard,項目名稱:joulepersecond-go,代碼行數:101,代碼來源:analysis.go

示例6: hpbz


//.........這裏部分代碼省略.........
	}
	clearVals := func() {
		sH1 = 0
		sH2 = 0
		sH3 = 0
		sH4 = 0
		sH5a = 0
		sH5b = 0
		sH5c = 0
		sP1 = 0
		sP2 = 0
		sP3 = 0
		sP4 = 0
		sP5 = 0
		sP6 = 0
	}
	//so now for each activity we have the sum of each of the zones (value for each second * number seconds) and the number of seconds to divide by later once summed by date
	//loope through each retrieved activity
	var lastActivity time.Time
	var numResult int

	for i := 1; i < len(temp_rows); i++ {
		if i == 1 {
			lastActivity = temp_rows[i].StartTime
		}

		//if we want to show data in monthly format
		if filter.Historylen > 366 { //show over 365 days as monthly
			//set last activity on first iteration only
			thisDate := temp_rows[i].StartTime
			prevDate := lastActivity

			//if we're still in the current month sum these values
			if thisDate.Month() != prevDate.Month() || i == len(temp_rows)-1 {
				var summedMonthlyHbz Hbz
				var summedMonthlyPbz Pbz

				summedMonthlyHbz.AvZ1 = utility.Round((float64(sH1) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ2 = utility.Round((float64(sH2) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ3 = utility.Round((float64(sH3) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ4 = utility.Round((float64(sH4) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ5a = utility.Round((float64(sH5a) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ5b = utility.Round((float64(sH5b) / 3600.0), .5, 2)
				summedMonthlyHbz.AvZ5c = utility.Round((float64(sH5c) / 3600.0), .5, 2)

				summedMonthlyPbz.AvZ1 = utility.Round((float64(sP1) / 3600.0), .5, 2)
				summedMonthlyPbz.AvZ2 = utility.Round((float64(sP2) / 3600.0), .5, 2)
				summedMonthlyPbz.AvZ3 = utility.Round((float64(sP3) / 3600.0), .5, 2)
				summedMonthlyPbz.AvZ4 = utility.Round((float64(sP4) / 3600.0), .5, 2)
				summedMonthlyPbz.AvZ5 = utility.Round((float64(sP5) / 3600.0), .5, 2)
				summedMonthlyPbz.AvZ6 = utility.Round((float64(sP6) / 3600.0), .5, 2)

				var month time.Month
				var year string

				if thisDate.Month() != prevDate.Month() {
					month = prevDate.Month()
					year = strconv.Itoa(prevDate.Year())
				} else {
					month = thisDate.Month()
					year = strconv.Itoa(thisDate.Year())
				}

				monthStr := month.String()
				summedMonthlyHbz.TimeLabel = monthStr[0:3] + " '" + year[2:4]
				summedMonthlyPbz.TimeLabel = monthStr[0:3] + " '" + year[2:4]
開發者ID:jezard,項目名稱:joulepersecond-go,代碼行數:67,代碼來源:analysis.go

示例7: GetDemandByAdspace

// Get demands by adspace id
func (c *PmpDemandPlatformDeskController) GetDemandByAdspace() {
	adspaceId := c.GetString("adspaceid")
	date := c.GetString("startdate")
	usetpl, err := c.GetBool("usetpl")
	beego.Info(" **** param adspaceid: " + adspaceId + " *** param startdate: " + date + " **** param usetpl: " + strconv.FormatBool(usetpl))
	if err != nil {
		usetpl = false
	}
	c.Data["maingridrowid"] = adspaceId
	c.Data["startdate"] = date
	if usetpl {
		//c.Data["json"] = &map[string]interface{}{"total": 2, "rows": []DemandVo{}}
		if c.GetTemplatetype() != "easyui" {
			c.Layout = c.GetTemplatetype() + "/public/layout.tpl"
		}
		c.TplNames = c.GetTemplatetype() + "/adspace/demand-easyui.tpl"
		return
	}
	const layout = "2006-1-2"
	startdate, _ := time.Parse(layout, date)
	startdate = startdate.Local()
	enddate := startdate.AddDate(0, 0, 6)
	dateend := enddate.Format(layout)
	beego.Info(" **** startdate:"+startdate.Format(layout), " **** enddate:", dateend)
	var dailyAllocations []models.PmpDailyAllocationVo
	adspaceIdInt, _ := strconv.Atoi(adspaceId)
	dailyAllocations = models.GetPmpDailyAllocationByAdspaceIdAndAdDate(adspaceIdInt, date, dateend)
	var demandVos []DemandVo
	var days [7]string
	var y, d int
	var m time.Month
	y, m, d = startdate.Date()
	days[0] = strconv.Itoa(y) + "-" + m.String() + "-" + strconv.Itoa(d)
	for i := 1; i < 7; i++ {
		startdate = startdate.AddDate(0, 0, 1)
		y, m, d = startdate.Date()
		days[i] = strconv.Itoa(y) + "-" + m.String() + "-" + strconv.Itoa(d)
	}
	var lastdemandadspaceid int = -1
	for _, v := range dailyAllocations {
		if lastdemandadspaceid != v.DemandAdspaceId {
			demandVos = append(demandVos, DemandVo{Name: v.Name, DemandAdspaceId: v.DemandAdspaceId, Proportion: v.Priority, DemandAdspaceName: v.DemandAdspaceName})
			lastdemandadspaceid = v.DemandAdspaceId
		}
		y, m, d := v.AdDate.Date()
		addate := strconv.Itoa(y) + "-" + m.String() + "-" + strconv.Itoa(d)
		for index, val := range days {
			var allocation int
			currIndex := len(demandVos) - 1

			if val == addate {
				allocation = v.Imp
				switch index {
				case 0:
					demandVos[currIndex].Day1 = allocation
				case 1:
					demandVos[currIndex].Day2 = allocation
				case 2:
					demandVos[currIndex].Day3 = allocation
				case 3:
					demandVos[currIndex].Day4 = allocation
				case 4:
					demandVos[currIndex].Day5 = allocation
				case 5:
					demandVos[currIndex].Day6 = allocation
				case 6:
					demandVos[currIndex].Day7 = allocation
				}
			}

		}

	}
	beego.Info("**** demandVos:", demandVos)
	c.Data["json"] = &map[string]interface{}{"total": len(demandVos), "rows": &demandVos}
	c.ServeJson()

}
開發者ID:wfnuser,項目名稱:o2oadmin,代碼行數:79,代碼來源:pmp_demand_platform_desk.go

示例8: MonthName

// Finds the US name for a given month
func (nc USCalendar) MonthName(month time.Month) string {
	return month.String()
}
開發者ID:xyproto,項目名稱:moskus,代碼行數:4,代碼來源:en_US.go

示例9: PrettyMonth

//template functions
func PrettyMonth(m time.Month) string {
	return m.String()[0:3] + "."
}
開發者ID:danmondy,項目名稱:everydaybham,代碼行數:4,代碼來源:main.go


注:本文中的Time.Month類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。