Skip to content

Commit

Permalink
ExifDateTime handles date formats without milliseconds or seconds now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Feb 5, 2023
1 parent a7a15cd commit fe935ad
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 331 deletions.
17 changes: 12 additions & 5 deletions src/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ export function isDateOrTime(o: any): o is DateOrTime {
o instanceof ExifDateTime ||
o instanceof ExifDate ||
o instanceof ExifTime ||
o instanceof DateTime
DateTime.isDateTime(o)
)
}

export function dateTimeToExif(d: DateTime): string {
return d.toFormat("y:MM:dd HH:mm:ss.u")
export function dateTimeToExif(
d: DateTime,
opts?: { includeOffset?: boolean; includeMilliseconds?: boolean }
): string {
return d.toFormat(
"y:MM:dd HH:mm:ss" +
(opts?.includeMilliseconds === true ? ".u" : "") +
(opts?.includeOffset === false ? "" : "ZZ")
)
}

export function toExifString(d: DateOrTime): Maybe<string> {
if (d instanceof DateTime) {
if (DateTime.isDateTime(d)) {
return dateTimeToExif(d)
} else {
return d.toExifString()
return d?.toExifString?.()
}
}
Loading

0 comments on commit fe935ad

Please sign in to comment.