mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Fixed serious error with offset calculation. Fixed bad test-data.
This commit is contained in:
parent
a6035f5b65
commit
a2c9208706
@ -197,23 +197,35 @@ export class MetadataLoader {
|
||||
|
||||
//function to convert timestamp into milliseconds taking offset into account
|
||||
const timestampToMS = (timestamp: string, offset: string) => {
|
||||
"replace first two : with - in timestamp string and add offset if exists (else +00:00 - UTC), parse this into MS"
|
||||
return Date.parse(timestamp.replace(':', '-').replace(':', '-') + (offset ? offset : '+00:00'));
|
||||
if (!timestamp) {
|
||||
return undefined;
|
||||
}
|
||||
//replace : with - in the yyyy-mm-dd part of the timestamp.
|
||||
let formattedTimestamp = timestamp.substring(0,9).replaceAll(':', '-') + timestamp.substring(9,timestamp.length);
|
||||
if (formattedTimestamp.indexOf("Z") > 0) { //replace Z (and what comes after the Z) with offset
|
||||
formattedTimestamp.substring(0, formattedTimestamp.indexOf("Z")) + (offset ? offset : '+00:00');
|
||||
} else if (formattedTimestamp.indexOf("+") > 0) { //don't do anything
|
||||
} else { //add offset
|
||||
formattedTimestamp = formattedTimestamp + (offset ? offset : '+00:00');
|
||||
}
|
||||
//parse into MS and return
|
||||
return Date.parse(formattedTimestamp);
|
||||
}
|
||||
|
||||
//function to calculate offset from exif.exif.gpsTimeStamp or exif.gps.GPSDateStamp + exif.gps.GPSTimestamp
|
||||
const getTimeOffsetByGPSStamp = (timestamp: string, gpsTimeStamp: string, gps: any) => {
|
||||
let UTCTimestamp = gpsTimeStamp; //use the exif.exif.gpsTimestamp if available
|
||||
let UTCTimestamp = gpsTimeStamp;
|
||||
if (!UTCTimestamp &&
|
||||
gps &&
|
||||
gps.GPSDateStamp &&
|
||||
gps.GPSTimeStamp) { //else use exif.gps.GPS*Stamp if available
|
||||
//GPS timestamp is always UTC (+00:00)
|
||||
UTCTimestamp = gps.GPSDateStamp.replaceAll(':', '-') + gps.GPSTimeStamp.join(':') + '+00:00';
|
||||
UTCTimestamp = gps.GPSDateStamp.replaceAll(':', '-') + gps.GPSTimeStamp.join(':');
|
||||
}
|
||||
if (UTCTimestamp) {
|
||||
if (UTCTimestamp && timestamp) {
|
||||
//offset in minutes is the difference between gps timestamp and given timestamp
|
||||
const offsetMinutes = (Date.parse(UTCTimestamp) - Date.parse(timestamp.replace(':', '-').replace(':', '-'))) / 1000 / 60;
|
||||
//to calculate this correctly, we have to work with the same offset
|
||||
const offsetMinutes = (timestampToMS(timestamp, '+00:00')- timestampToMS(UTCTimestamp, '+00:00')) / 1000 / 60;
|
||||
if (-720 <= offsetMinutes && offsetMinutes <= 840) {
|
||||
//valid offset is within -12 and +14 hrs (https://en.wikipedia.org/wiki/List_of_UTC_offsets)
|
||||
return (offsetMinutes < 0 ? "-" : "+") + //leading +/-
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
@ -5,7 +5,7 @@
|
||||
},
|
||||
"creationDate": 1600512957000,
|
||||
"creationDateOffset": "+10:00",
|
||||
"fileSize": 22653,
|
||||
"fileSize": 22641,
|
||||
"cameraData": {
|
||||
"model": "ILCE-7RM3",
|
||||
"make": "Sony"
|
||||
|
Loading…
Reference in New Issue
Block a user