mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
e59fdded1b
commit
f2a89063c6
3 changed files with 23 additions and 3 deletions
|
|
@ -12,5 +12,5 @@ func Strip(t time.Time) (result time.Time) {
|
|||
|
||||
result, _ = time.ParseInLocation("2006:01:02 15:04:05", t.Format("2006:01:02 15:04:05"), time.UTC)
|
||||
|
||||
return result
|
||||
return result.Truncate(time.Second)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ func TruncateUTC(t time.Time) time.Time {
|
|||
// LocationUTC returns the time at the locale with the time zone set to UTC.
|
||||
func LocationUTC(t time.Time, loc *time.Location) (result time.Time) {
|
||||
var err error
|
||||
if result, err = time.ParseInLocation("2006-01-02T15:04:05", t.In(loc).Format("2006-01-02T15:04:05"), time.UTC); err != nil {
|
||||
return result
|
||||
if result, err = time.ParseInLocation("2006-01-02T15:04:05", t.In(loc).Format("2006-01-02T15:04:05"), time.UTC); err == nil {
|
||||
return result.Truncate(time.Second)
|
||||
} else {
|
||||
return t
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,3 +35,23 @@ func TestTruncateUTC(t *testing.T) {
|
|||
assert.NotEqual(t, ns, result.Nanosecond())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocationUTC(t *testing.T) {
|
||||
loc := Find("Europe/Berlin")
|
||||
now := time.Now().In(loc).UTC()
|
||||
ns := now.Nanosecond()
|
||||
|
||||
t.Logf("now: %s", now.String())
|
||||
|
||||
result := LocationUTC(now, loc)
|
||||
|
||||
t.Logf("result: %s", result.String())
|
||||
|
||||
assert.Equal(t, TimeUTC, result.Location())
|
||||
timeZone, _ := result.Zone()
|
||||
assert.Equal(t, UTC, timeZone)
|
||||
assert.Equal(t, 0, result.Nanosecond())
|
||||
if ns > 0 {
|
||||
assert.NotEqual(t, ns, result.Nanosecond())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue