+// scheduleWallTime returns the time of a wall time in location. A wall time
+// that the clock skips, at the start of daylight saving time, is later by the
+// length of the skip: 02:30 becomes 03:30 when the clock goes from 02:00 to
+// 03:00. A wall time that the clock repeats, at the end of daylight saving
+// time, is its first occurrence, as in cron.
+func scheduleWallTime(year int, month time.Month, day, hour, minute int, location *time.Location) time.Time {
+ t := time.Date(year, month, day, hour, minute, 0, 0, location)
+ _, before := t.Add(-3 * time.Hour).Zone()
+ _, offset := t.Zone()
+ if t.Hour() != hour || t.Minute() != minute || t.Day() != day {
+ wall := time.Date(year, month, day, hour, minute, 0, 0, time.UTC)
+
+ return wall.Add(-time.Duration(before) * time.Second).In(location)
+ }
+
+ if before > offset {
+ earlier := t.Add(-time.Duration(before-offset) * time.Second)
+ if earlier.Day() == day && earlier.Hour() == hour && earlier.Minute() == minute {
+ return earlier
+ }
+ }
+
+ return t
+}
+