Reputation: 528
I am trying to create this block of code:
var nextWorkday time.Date
// var nextWorkday *time.Date // neither works
yyyy, mm, dd := now.Date()
goalTime, _ := time.ParseDuration(fmt.Sprintf("%fh", *goal))
goalSeconds := int(goalTime.Seconds())
if date.Weekday() != time.Friday { // wait till the next workday (7am + difference)
nextWorkday = time.Date(yyyy, mm, dd+1, 7, 0, 0+goalSeconds, 0, now.Location())
} else {
nextWorkday = time.Date(yyyy, mm, dd+3, 7, 0, 0+goalSeconds, 0, now.Location())
}
time.Sleep(nextWorkday)
The important breaking point is already the first line. I do not know how to declare a new variable of a custom type. Right now I get the error:
time.Date is not a type
What am I doing wrong? Any help appreciated!
Upvotes: 3
Views: 6711
Reputation: 418377
There is no time.Date
type in the standard time
package. There is however a time.Time
type which represents a time instant, "including" date.
time.Date()
is a function which constructs a time.Time
value from the provided date and time fields.
Upvotes: 8