Migrate: Default to UTC when reading time from XMP #636
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
5af3ca72fa
commit
b708b963c2
4 changed files with 43 additions and 11 deletions
21
internal/meta/testdata/date.heic.xmp
vendored
Normal file
21
internal/meta/testdata/date.heic.xmp
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:exif="http://ns.adobe.com/exif/1.0/"
|
||||
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
|
||||
<exif:GPSHPositioningError>35</exif:GPSHPositioningError>
|
||||
<exif:GPSImgDirection>193.66278065630397</exif:GPSImgDirection>
|
||||
<exif:GPSAltitudeRef>0</exif:GPSAltitudeRef>
|
||||
<exif:GPSAltitude>63.631790123456788</exif:GPSAltitude>
|
||||
<exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
|
||||
<exif:GPSLatitude>47.675403333333335</exif:GPSLatitude>
|
||||
<exif:GPSLongitudeRef>W</exif:GPSLongitudeRef>
|
||||
<exif:GPSLongitude>122.31739166666667</exif:GPSLongitude>
|
||||
<exif:GPSImgDirectionRef>T</exif:GPSImgDirectionRef>
|
||||
<exif:GPSSpeed>0.0</exif:GPSSpeed>
|
||||
<exif:GPSSpeedRef>K</exif:GPSSpeedRef>
|
||||
<exif:GPSTimeStamp>2022-09-04T00:48:27Z</exif:GPSTimeStamp>
|
||||
<photoshop:DateCreated>2022-09-03T17:48:26-07:00</photoshop:DateCreated>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
|
||||
|
@ -64,8 +65,11 @@ func (data *Data) XMP(fileName string) (err error) {
|
|||
data.LensModel = doc.LensModel()
|
||||
}
|
||||
|
||||
if takenAt := doc.TakenAt(); !takenAt.IsZero() {
|
||||
data.TakenAt = takenAt
|
||||
if takenAt := doc.TakenAt(data.TimeZone); !takenAt.IsZero() {
|
||||
data.TakenAt = takenAt.UTC()
|
||||
if data.TimeZone == "" {
|
||||
data.TimeZone = time.UTC.String()
|
||||
}
|
||||
}
|
||||
|
||||
if len(doc.Keywords()) != 0 {
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/txt"
|
||||
)
|
||||
|
||||
// XmpDocument represents an XMP sidecar file.
|
||||
|
@ -259,7 +261,7 @@ func (doc *XmpDocument) LensModel() string {
|
|||
}
|
||||
|
||||
// TakenAt returns the XMP document taken date.
|
||||
func (doc *XmpDocument) TakenAt() time.Time {
|
||||
func (doc *XmpDocument) TakenAt(timeZone string) time.Time {
|
||||
taken := time.Time{} // Unknown
|
||||
|
||||
s := SanitizeString(doc.RDF.Description.DateCreated)
|
||||
|
@ -268,14 +270,8 @@ func (doc *XmpDocument) TakenAt() time.Time {
|
|||
return taken
|
||||
}
|
||||
|
||||
if t, err := time.Parse(time.RFC3339, s); err == nil {
|
||||
taken = t
|
||||
} else if t, err := time.Parse("2006-01-02T15:04:05.999999999", s); err == nil {
|
||||
taken = t
|
||||
} else if t, err := time.Parse("2006-01-02T15:04:05Z07:00", s); err == nil {
|
||||
taken = t
|
||||
} else if t, err := time.Parse("2006-01-02T15:04:05", s[:19]); err == nil {
|
||||
taken = t
|
||||
if dateTime := txt.DateTime(s, timeZone); !dateTime.IsZero() {
|
||||
return dateTime
|
||||
}
|
||||
|
||||
return taken
|
||||
|
|
|
@ -70,4 +70,15 @@ func TestXMP(t *testing.T) {
|
|||
assert.Equal(t, "iPhone 7 back camera 3.99mm f/1.8", data.LensModel)
|
||||
})
|
||||
|
||||
t.Run("DateHeic", func(t *testing.T) {
|
||||
data, err := XMP("testdata/date.heic.xmp")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, time.Date(2022, 9, 4, 0, 48, 26, 0, time.UTC), data.TakenAt.UTC())
|
||||
assert.True(t, data.TakenAtLocal.IsZero())
|
||||
assert.Equal(t, "UTC", data.TimeZone)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue