mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
Attempt to fix broken timezone test
This commit is contained in:
parent
4f8e857b05
commit
d39ca42cea
@ -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) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ddworken/hishtory/shared"
|
"github.com/ddworken/hishtory/shared"
|
||||||
@ -29,8 +28,6 @@ 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?
|
|
||||||
if os.Getenv("GITHUB_ACTIONS") == "" {
|
|
||||||
ts, err = parseTimeGenerously("2006-01-02T15:04:00")
|
ts, err = parseTimeGenerously("2006-01-02T15:04:00")
|
||||||
shared.Check(t, err)
|
shared.Check(t, err)
|
||||||
if ts.Unix() != 1136243040 {
|
if ts.Unix() != 1136243040 {
|
||||||
@ -41,7 +38,6 @@ 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())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ts, err = parseTimeGenerously("2006-01-02")
|
ts, err = parseTimeGenerously("2006-01-02")
|
||||||
shared.Check(t, err)
|
shared.Check(t, err)
|
||||||
if ts.Unix() != 1136160000 {
|
if ts.Unix() != 1136160000 {
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user