Skip to content

Commit

Permalink
Merge branch 'main' of github.com:photostructure/exiftool-vendored.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Sep 22, 2024
2 parents 7d7d812 + 36c1090 commit 638ab8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Timezones.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ describe("Timezones", () => {
})

describe("extractTzOffsetFromUTCOffset", () => {
it("with DateTimeUTC offset by 4 hours and lagging by one second from DateTimeOriginal", () => {
expect(
extractTzOffsetFromUTCOffset({
DateTimeOriginal: "2024:09:14 12:00:00",
DateTimeUTC: "2024:09:14 16:00:01",
})
).to.eql({
tz: "UTC-4",
src: "offset between DateTimeOriginal and DateTimeUTC",
})
})
it("with lagging GPSDateStamp & GPSTimeStamp and DateTimeOriginal in negative offset", () => {
expect(
extractTzOffsetFromUTCOffset({
Expand Down
15 changes: 12 additions & 3 deletions src/Timezones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,20 @@ export function extractTzOffsetFromDatestamps(
// old, this can be spurious. We get less mistakes with a larger multiple, so
// we're using 30 minutes instead of 15. See
// https://www.timeanddate.com/time/time-zones-interesting.html

const TzBoundaryMinutes = 30
const LikelyOffsetMinutes = ValidTimezoneOffsets
.filter((offset) => offset.endsWith(":00") || offset.endsWith(":30"))
.map(offsetToMinutes)

export function inferLikelyOffsetMinutes(deltaMinutes: number): number {
return TzBoundaryMinutes * Math.floor(deltaMinutes / TzBoundaryMinutes)
// More then a day away? nothing is likely
if (Math.abs(deltaMinutes) > (24 * 60)) return deltaMinutes

return LikelyOffsetMinutes
.reduce((prev, curr) =>
Math.abs(curr - deltaMinutes) < Math.abs(prev - deltaMinutes)
? curr
: prev
)
}

/**
Expand Down

0 comments on commit 638ab8d

Please sign in to comment.