Attempt to fix broken timezone test

This commit is contained in:
David Dworken 2022-04-11 22:56:23 -07:00
parent 4f8e857b05
commit d39ca42cea
3 changed files with 14 additions and 16 deletions

View File

@ -73,7 +73,7 @@ func Encrypt(userSecret string, data, additionalData []byte) ([]byte, []byte, er
ciphertext := aead.Seal(nil, nonce, data, additionalData) ciphertext := aead.Seal(nil, nonce, data, additionalData)
_, err = aead.Open(nil, nonce, ciphertext, additionalData) _, err = aead.Open(nil, nonce, ciphertext, additionalData)
if err != nil { if err != nil {
panic(err) return []byte{}, []byte{}, fmt.Errorf("failed to open AEAD: %v", err)
} }
return ciphertext, nonce, nil return ciphertext, nonce, nil
} }
@ -132,7 +132,7 @@ func parseTimeGenerously(input string) (time.Time, error) {
} }
_, offset := time.Now().Zone() _, offset := time.Now().Zone()
if offset%(60*60) != 0 { if offset%(60*60) != 0 {
panic("timezone isn't aligned on the hour! This is unimplemented!") return time.Now(), fmt.Errorf("timezone offset=%d isn't aligned on the hour, this is unimplemented", offset)
} }
inputWithTimeZone := fmt.Sprintf("%s %03d00", input, (offset / 60 / 60)) inputWithTimeZone := fmt.Sprintf("%s %03d00", input, (offset / 60 / 60))
t, err = time.Parse("2006-01-02T15:04:05 -0700", inputWithTimeZone) t, err = time.Parse("2006-01-02T15:04:05 -0700", inputWithTimeZone)
@ -147,7 +147,7 @@ func parseTimeGenerously(input string) (time.Time, error) {
if err == nil { if err == nil {
return t.Local(), nil return t.Local(), nil
} }
return time.Now(), fmt.Errorf("failed to parse time %#v, please format like \"2006-01-02T15:04\" or like \"2006-01-02\"", input) return time.Now(), fmt.Errorf("failed to parse time %#v (attempted to parse as %#v or %#v), please format like \"2006-01-02T15:04\" or like \"2006-01-02\"", input, input, inputWithTimeZone)
} }
func Search(db *gorm.DB, query string, limit int) ([]*HistoryEntry, error) { func Search(db *gorm.DB, query string, limit int) ([]*HistoryEntry, error) {

View File

@ -1,7 +1,6 @@
package data package data
import ( import (
"os"
"testing" "testing"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
@ -29,18 +28,15 @@ func TestParseTimeGenerously(t *testing.T) {
if ts.Unix() != 1136243040 { if ts.Unix() != 1136243040 {
t.Fatalf("parsed time incorrectly: %d", ts.Unix()) t.Fatalf("parsed time incorrectly: %d", ts.Unix())
} }
// TODO: debug why these tests fail on github actions, I probably have broken logic for timezones? ts, err = parseTimeGenerously("2006-01-02T15:04:00")
if os.Getenv("GITHUB_ACTIONS") == "" { shared.Check(t, err)
ts, err = parseTimeGenerously("2006-01-02T15:04:00") if ts.Unix() != 1136243040 {
shared.Check(t, err) t.Fatalf("parsed time incorrectly: %d", ts.Unix())
if ts.Unix() != 1136243040 { }
t.Fatalf("parsed time incorrectly: %d", ts.Unix()) ts, err = parseTimeGenerously("2006-01-02T15:04")
} shared.Check(t, err)
ts, err = parseTimeGenerously("2006-01-02T15:04") if ts.Unix() != 1136243040 {
shared.Check(t, err) t.Fatalf("parsed time incorrectly: %d", ts.Unix())
if ts.Unix() != 1136243040 {
t.Fatalf("parsed time incorrectly: %d", ts.Unix())
}
} }
ts, err = parseTimeGenerously("2006-01-02") ts, err = parseTimeGenerously("2006-01-02")
shared.Check(t, err) shared.Check(t, err)

View File

@ -41,6 +41,8 @@ func main() {
lib.CheckFatalError(lib.Enable()) lib.CheckFatalError(lib.Enable())
case "disable": case "disable":
lib.CheckFatalError(lib.Disable()) lib.CheckFatalError(lib.Disable())
case "version":
fallthrough
case "status": case "status":
config, err := lib.GetConfig() config, err := lib.GetConfig()
lib.CheckFatalError(err) lib.CheckFatalError(err)