Browse Source

WIP WIP, nae nae Exists, IsAmbiguous

master
AJ ONeal 5 years ago
parent
commit
e09133ae54
  1. 95
      time.go

95
time.go

@ -43,36 +43,28 @@ func main() {
/* funky times */
tz := "America/Denver"
fmt.Println("funky")
CheckInput2([]int{2019, 3, 10,
01, 59, 00, 0}, tz)
CheckInput2([]int{2019, 3, 10,
02, 00, 00, 0}, tz)
CheckInput2([]int{2019, 3, 10,
02, 01, 00, 0}, tz)
CheckInput2([]int{2019, 3, 10,
02, 59, 00, 0}, tz)
CheckInput2([]int{2019, 3, 10,
03, 00, 00, 0}, tz)
CheckInput2([]int{2019, 3, 10,
03, 01, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
0, 59, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
01, 59, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
02, 00, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
02, 01, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
02, 59, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
03, 00, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
03, 01, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
04, 01, 00, 0}, tz)
CheckInput2([]int{2019, 11, 03,
05, 01, 00, 0}, tz)
for _, st := range [][]int{
[]int{2019, 3, 10, 01, 59, 00, 0},
[]int{2019, 3, 10, 02, 00, 00, 0},
[]int{2019, 3, 10, 02, 01, 00, 0},
[]int{2019, 3, 10, 02, 59, 00, 0},
[]int{2019, 3, 10, 03, 00, 00, 0},
[]int{2019, 3, 10, 03, 01, 00, 0},
[]int{2019, 11, 03, 0, 59, 00, 0},
[]int{2019, 11, 03, 01, 59, 00, 0},
[]int{2019, 11, 03, 02, 00, 00, 0},
[]int{2019, 11, 03, 02, 01, 00, 0},
[]int{2019, 11, 03, 02, 59, 00, 0},
[]int{2019, 11, 03, 03, 00, 00, 0},
[]int{2019, 11, 03, 03, 01, 00, 0},
[]int{2019, 11, 03, 04, 01, 00, 0},
[]int{2019, 11, 03, 05, 01, 00, 0},
} {
err := IsAmbiguous(st, tz)
if nil != err {
fmt.Println(err)
}
}
}
type ErrNoExist struct {
@ -87,9 +79,9 @@ func (err ErrNoExist) Error() string {
// Check if the time is a real time in the given timezone.
//
// For example: 2:30am doesn't happen on 2019 Nov 3rd according
// For example: 2:30am doesn't happen on 2019 March 10th according
// to America/Denver local time, due to the end of Daylight Savings Time,
// but it did happen in America/Phoenix.
// but it does happen in America/Phoenix.
//
// Also rejects times that are parsable and return a valid date object,
// but are not canonical, such as 24:60:75 November 31st, 2020.
@ -97,13 +89,20 @@ func (err ErrNoExist) Error() string {
//
// Example of parsable, but non-canonical time:
//
// fmt.Println(time.Date(2020, time.November, 31, 25, 60, 0, 0, time.UTC))
// "2020-12-02 02:01:15 +0000 UTC"
// var loc *time.Location
// loc, _ = time.LoadLocation("America/Denver")
// t := time.Date(2019, time.March, 10, 1, 30, 0, 0, loc)
// fmt.Println(t, "==", t.UTC())
// // 2019-03-10 01:30:00 -0700 MST == 2019-03-10 08:30:00 +0000 UTC
// t = t.Add(time.Duration(1) * time.Hour)
// fmt.Println(t, "==", t.UTC())
// // 2019-03-10 03:30:00 -0600 MDT == 2019-03-10 09:30:00 +0000 UTC
//
// Example of a canonical, but non-parsable time (the 2016 leap second):
//
// fmt.Println(time.Date(2016, time.December, 31, 23, 59, 60, 0, time.UTC))
// "2020-12-02 02:00:00 +0000 UTC" // should be "2016-12-31 23:59:60 +0000 UTC"
//
func Exists(st []int, tzstr string) error {
tz, err := time.LoadLocation(tzstr)
if nil != err {
@ -158,11 +157,27 @@ func Exists(st []int, tzstr string) error {
return nil
}
func IsAmbigious(st []int, tzstr string) error {
return fmt.Errorf("Not Implemented")
}
func CheckInput2(st []int, tzstr string) error {
// Check if the time happens more than once in a given timezone.
//
// For example: 1:30am happens only once on 2019 Nov 3rd according to
// America/Phoenix time but due to the start of Daylight Savings Time,
// it happens twice in America/Denver.
//
// Example of duplicate, non-canonical time:
//
// var loc *time.Location
// loc, _ = time.LoadLocation("America/Denver")
// t = time.Date(2019, time.November, 3, 1, 30, 0, 0, loc)
// fmt.Println(t, "==", t.UTC())
// // 2019-11-03 01:30:00 -0600 MDT == 2019-11-03 07:30:00 +0000 UTC
// t = t.Add(time.Duration(1) * time.Hour)
// fmt.Println(t, "==", t.UTC())
// // 2019-11-03 01:30:00 -0700 MST == 2019-11-03 08:30:00 +0000 UTC
// t = t.Add(time.Duration(1) * time.Hour)
// fmt.Println(t, "==", t.UTC())
// // 2019-11-03 02:30:00 -0700 MST == 2019-11-03 09:30:00 +0000 UTC
//
func IsAmbiguous(st []int, tzstr string) error {
// Does the time exist twice?
// (if I change the time in UTC, do I still get the same time)
// Note: Some timezones change by half or quarter hour
@ -190,7 +205,7 @@ func CheckInput2(st []int, tzstr string) error {
fmt.Println("Ambiguous Time")
fmt.Printf("%s, %s, %+d\n", t1, u1, n)
fmt.Printf("%s, %s, %+d\n", t2, u2, n)
return nil
return fmt.Errorf("Ambiguous")
}
}
//ta :=

Loading…
Cancel
Save