Skip to content

Commit

Permalink
Improved jsdocs and removed extraneous call to fromISO()
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Nov 14, 2022
1 parent 75b53b0 commit cbe026a
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/ExifDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ZoneOptions,
} from "luxon"
import { dateTimeToExif } from "./DateTime"
import { denull, firstDefinedThunk, Maybe } from "./Maybe"
import { denull, Maybe } from "./Maybe"
import { omit } from "./Object"
import { blank, notBlank, toS } from "./String"
import {
Expand Down Expand Up @@ -41,11 +41,12 @@ export class ExifDateTime {
}

/**
* Try to parse a date-time string from EXIF. If there is not both a date and
* a time component, returns `undefined`.
* Try to parse a date-time string from EXIF. If there is not both a date
* and a time component, returns `undefined`.
*
* @param text from EXIF metadata
* @param defaultZone a "zone name" which may be IANA, like
* @param defaultZone a "zone name" to use as a backstop, or default, if
* `text` doesn't specify a zone. This may be IANA-formatted, like
* "America/Los_Angeles", or an offset, like "UTC-3". See
* `offsetMinutesToZoneName`.
*/
Expand All @@ -54,11 +55,11 @@ export class ExifDateTime {
defaultZone?: Maybe<string>
): Maybe<ExifDateTime> {
if (blank(text)) return undefined
return firstDefinedThunk([
() => this.fromExifStrict(text, defaultZone),
() => this.fromISO(text, defaultZone),
() => this.fromExifLoose(text, defaultZone),
])
return (
// .fromExifStrict() uses .fromISO() as a backstop
this.fromExifStrict(text, defaultZone) ??
this.fromExifLoose(text, defaultZone)
)
}

private static fromPatterns(
Expand Down Expand Up @@ -93,9 +94,20 @@ export class ExifDateTime {
return
}

/**
* Parse the given date-time string, EXIF-formatted.
*
* @param text from EXIF metadata, in `y:M:d H:m:s` format (with optional
* sub-seconds and/or timezone)
* @param defaultZone a "zone name" to use as a backstop, or default, if
* `text` doesn't specify a zone. This may be IANA-formatted, like
* "America/Los_Angeles", or an offset, like "UTC-3". See
* `offsetMinutesToZoneName`.
*/
static fromExifStrict(
text: Maybe<string>,
zone?: Maybe<string>
defaultZone?: Maybe<string>
): Maybe<ExifDateTime> {
if (blank(text)) return undefined
return (
Expand All @@ -109,11 +121,12 @@ export class ExifDateTime {
{ fmt: "y:M:d H:m:s'Z'", zone: "utc" },

// Otherwise use the default zone:
{ fmt: "y:M:d H:m:s.u", zone },
{ fmt: "y:M:d H:m:s", zone },
{ fmt: "y:M:d H:m:s.u", zone: defaultZone },
{ fmt: "y:M:d H:m:s", zone: defaultZone },

// Not found yet? Maybe it's in ISO format? See https://github.com/photostructure/exiftool-vendored.js/issues/71
]) ?? this.fromISO(text, zone)
// Not found yet? Maybe it's in ISO format? See
// https://github.com/photostructure/exiftool-vendored.js/issues/71
]) ?? this.fromISO(text, defaultZone)
)
}

Expand Down

0 comments on commit cbe026a

Please sign in to comment.