本文整理匯總了Golang中Time.Time.ISOWeek方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.ISOWeek方法的具體用法?Golang Time.ISOWeek怎麽用?Golang Time.ISOWeek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Time.Time
的用法示例。
在下文中一共展示了Time.ISOWeek方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newTime
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}
}
示例2: convertTimeFormat
func convertTimeFormat(t time.Time, n byte) string {
switch n {
case 'a':
return t.Weekday().String()[:3]
case 'A':
return t.Weekday().String()
case 'b':
return t.Month().String()[:3]
case 'B':
return t.Month().String()
case 'c':
return t.Format("ANSIC")
case 'd':
return fmt.Sprintf("%02d", t.Day())
case 'H':
return fmt.Sprintf("%02d", t.Hour())
case 'I':
hr := t.Hour() % 12
if hr == 0 {
hr = 12
}
return fmt.Sprintf("%02d", hr)
case 'm':
return fmt.Sprintf("%02d", t.Month())
case 'M':
return fmt.Sprintf("%02d", t.Minute())
case 'p':
if t.Hour() > 11 {
return "PM"
}
return "AM"
case 'S':
return fmt.Sprintf("%02d", t.Second())
case 'x':
return t.Format("Mon Jan 02")
case 'X':
return t.Format("15:04:05")
case 'y':
year := fmt.Sprintf("%04d", t.Year())
if l := len(year); l > 2 {
return year[l-2 : l]
}
return year
case 'Y':
return fmt.Sprintf("%04d", t.Year())
case 'j':
return fmt.Sprintf("%02d", t.YearDay())
case 'w':
return fmt.Sprintf("%02d", t.Weekday())
case 'U':
_, w := t.ISOWeek()
return fmt.Sprintf("%02d", w)
case 'W':
_, w := t.ISOWeek()
return fmt.Sprintf("%02d", w)
default:
return string(n)
}
}
示例3: same
func same(d date.Date, t time.Time) bool {
yd, wd := d.ISOWeek()
yt, wt := t.ISOWeek()
return d.Year() == t.Year() &&
d.Month() == t.Month() &&
d.Day() == t.Day() &&
d.Weekday() == t.Weekday() &&
d.YearDay() == t.YearDay() &&
yd == yt && wd == wt
}
示例4: PeriodHeadline
func PeriodHeadline(from, to time.Time, period datetime.Period) string {
switch period {
case datetime.Day:
return fmt.Sprintf("%s", from.Format("2006-01-02: Monday"))
case datetime.Week:
_, isoWeek := from.ISOWeek()
return fmt.Sprintf("Week %d: %s - %s", isoWeek, from.Format("2006-01-02"), to.Format("2006-01-02"))
case datetime.Month:
return fmt.Sprintf("%s", from.Format("January 2006"))
case datetime.Year:
return fmt.Sprintf("%s", from.Format("Year 2006"))
default:
panic("not implemeneted")
}
}
示例5: NewDateFromTime
func NewDateFromTime(time time.Time) Date {
date := Date{}
date.Date = time.Format("2006-01-02")
date.Weekend = isWeekend(time)
date.Day = time.Weekday().String()
_, date.WeekNumber = time.ISOWeek()
return date
}
示例6: indexName
func indexName(project *engine.ConfProject, indexPattern string,
date time.Time) (index string) {
const (
YM = "@ym"
YMW = "@ymw"
YMD = "@ymd"
INDEX_PREFIX = "fun_"
)
if strings.Contains(indexPattern, YM) {
prefix := project.IndexPrefix
fields := strings.SplitN(indexPattern, YM, 2)
if fields[0] != "" {
// e,g. [email protected]
prefix = fields[0]
}
switch indexPattern {
case YM:
index = fmt.Sprintf("%s%s_%d_%02d", INDEX_PREFIX, prefix,
date.Year(), int(date.Month()))
case YMW:
year, week := date.ISOWeek()
index = fmt.Sprintf("%s%s_%d_w%02d", INDEX_PREFIX, prefix,
year, week)
case YMD:
index = fmt.Sprintf("%s%s_%d_%02d_%02d", INDEX_PREFIX, prefix,
date.Year(), int(date.Month()), date.Day())
}
return
}
index = INDEX_PREFIX + indexPattern
return
}
示例7: initTime
func (c *ctx) initTime(config *ctxConfig, t time.Time) {
if config.date {
c.year, c.month, c.day = t.Date()
}
if config.clock {
c.hour, c.min, c.sec = t.Clock()
}
if config.iso {
c.isoYear, c.isoWeek = t.ISOWeek()
}
if config.millis {
c.millis = t.Nanosecond() / 1000000
}
if config.yearday {
c.yearday = t.YearDay()
}
if config.weekday {
c.weekday = t.Weekday()
}
}
示例8: PeriodTypeByWeek
func PeriodTypeByWeek(week int64) int64 {
t := time.Now().UTC()
var t2 time.Time
current_year := t.Year()
fmt.Println(current_year)
current_month := int(t.Month())
_, start_week := t.ISOWeek()
if current_month >= 9 {
t2, _ = time.Parse("1.2.2006", fmt.Sprintf("%d.%d.%d", 9, 1, current_year))
} else {
t2, _ = time.Parse("1.2.2006", fmt.Sprintf("%d.%d.%d", 9, 1, current_year-1))
}
t2 = t2.UTC()
_, start_week = t2.ISOWeek()
var pt int64
pt = 1
if start_week%2 != 0 && week%2 == 0 {
pt = 2
} else if start_week%2 == 0 && week%2 != 0 {
pt = 2
}
return pt
}
示例9: RoundDown
func (w Week) RoundDown(t time.Time) time.Time {
org := t.Format("Mon 2006-01-02")
_, week := t.ISOWeek()
shift := int64(60 * 60 * 24 * (t.Weekday() - time.Monday))
t = t.Add(-time.Duration(shift) * time.Second)
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
// daylight saving and that like might lead to different real shift
_, week2 := t.ISOWeek()
for week2 < week {
trace.Printf("B %s", t)
t = t.Add(time.Second * 60 * 60 * 36)
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
_, week2 = t.ISOWeek()
}
for week2 > week {
trace.Printf("C %s", t)
t = t.Add(-time.Second * 60 * 60 * 36)
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
_, week2 = t.ISOWeek()
}
trace.Printf("Week.Roundown(%s) --> %s", org, t.Format("Mon 2006-01-02"))
return t
}
示例10: yw
// yw returns an integer in the form YYYYWW, where WW is the week number.
func yw(d time.Time) int {
year, week := d.ISOWeek()
return year*100 + week
}
示例11: datePart
func datePart(part string, t time.Time) (*dparval.Value, error) {
// now look for the requested part
switch part {
case "century":
cen := float64(t.Year() / 100.0)
if cen > 0 {
cen = cen + 1 // there is no century 0
}
return dparval.NewValue(cen), nil
case "day":
return dparval.NewValue(float64(t.Day())), nil
case "decade":
return dparval.NewValue(float64(t.Year() / 10.0)), nil
case "dow":
return dparval.NewValue(float64(t.Weekday())), nil
case "doy":
return dparval.NewValue(float64(t.YearDay())), nil
case "epoch":
return dparval.NewValue(float64(t.Unix())), nil
case "hour":
return dparval.NewValue(float64(t.Hour())), nil
case "isodow":
isodow := float64(t.Weekday())
if isodow == 0.0 {
isodow = 7.0
}
return dparval.NewValue(isodow), nil
case "isoyear":
y, _ := t.ISOWeek()
return dparval.NewValue(float64(y)), nil
case "microseconds":
us := float64(t.Second() * 1000000)
us = us + float64(t.Nanosecond()/int(time.Microsecond))
return dparval.NewValue(us), nil
case "millennium":
mil := float64(t.Year() / 1000.0)
if mil > 0 {
mil = mil + 1 // there is no millennium 0
}
return dparval.NewValue(mil), nil
case "milliseconds":
ms := float64(t.Second() * 1000)
ms = ms + float64(t.Nanosecond()/int(time.Millisecond))
return dparval.NewValue(ms), nil
case "minute":
return dparval.NewValue(float64(t.Minute())), nil
case "month":
return dparval.NewValue(float64(t.Month())), nil
case "quarter":
return dparval.NewValue(math.Ceil(float64(t.Month()) / 3.0)), nil
case "second":
return dparval.NewValue(float64(t.Second())), nil
case "timezone":
_, z := t.Zone()
return dparval.NewValue(float64(z)), nil
case "timezone_hour":
_, z := t.Zone()
zh := int64(z / (60 * 60))
return dparval.NewValue(float64(zh)), nil
case "timezone_minute":
_, z := t.Zone()
zh := int(z / (60 * 60))
z = z - (zh * (60 * 60))
zm := int64(z / 60)
return dparval.NewValue(float64(zm)), nil
case "week":
_, w := t.ISOWeek()
return dparval.NewValue(float64(w)), nil
case "year":
return dparval.NewValue(float64(t.Year())), nil
default:
return nil, fmt.Errorf("Unknown date part %s", part)
}
}
示例12: timetuple
func timetuple(t time.Time) [5]int {
year, month, day := t.Date()
_, week := t.ISOWeek()
return [5]int{year, int(month), day, t.Hour(), week}
}
示例13: Format
func (w Week) Format(t time.Time) string {
_, week := t.ISOWeek()
return fmt.Sprintf("W %d", week)
}
示例14: isSameWeek
func isSameWeek(date1 time.Time, date2 time.Time) bool {
y1, w1 := date1.ISOWeek()
y2, w2 := date2.ISOWeek()
return y1 == y2 && w1 == w2
}
示例15: cmdCreateMilestone
// cmdCreateMilestone creates a new milestone in all projects
func cmdCreateMilestone(opts *Options, target, due, title string) error {
tc := AuthClient(opts)
client := github.NewClient(tc)
config, err := LoadConfig(opts)
if err != nil {
return err
}
var date time.Time
if due != "" {
date, err = time.Parse("2006-01-02", due)
if err != nil {
return err
}
} else {
// Default to Monday next week with a little wiggle room
check := time.Now().Add(5 * 24 * time.Hour)
check = check.Round(1 * 24 * time.Hour)
check = check.Add(1 * time.Second)
for check.Weekday() != 0 {
check = check.Add(1 * 24 * time.Hour)
}
date = check
}
if title == "" {
year, week := date.ISOWeek()
seed, err := strconv.Atoi(fmt.Sprintf("%d%02d", year, week))
if err != nil {
return err
}
rand.Seed(int64(seed))
ship := Titles[rand.Intn(len(Titles))]
title = fmt.Sprintf("%d-%02d %s", year, week, ship)
}
var projects []string
if target == "all" {
projects = config.Projects
} else {
projects = strings.Split(target, " ")
}
for _, project := range projects {
logger.Debugln("Creating milestone for:", project)
owner, repo, err := ownerRepo(project)
if err != nil {
return err
}
// if we got here we didn't match, create a milestone
logger.Debugf(" creating: %s (%v)", title, due)
_, _, err = client.Issues.CreateMilestone(owner, repo, &github.Milestone{Title: &title, DueOn: &date})
if err != nil {
return err
}
}
fmt.Printf("New Milestone: %s\n", title)
return nil
}