mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-12-23 01:27:14 +02:00
Updated zeroPrefix to get rid of deprecation warning and to make it more generic
This commit is contained in:
parent
b979b476bd
commit
e2fedb26a1
@ -56,12 +56,16 @@ export class Utils {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: use zeroPad which works for longer values?
|
static zeroPrefix(number: any, length: number): string {
|
||||||
static zeroPrefix(value: string | number, length: number): string {
|
if (!isNaN(number)) {
|
||||||
const ret = '00000' + value;
|
const zerosToAdd = Math.max(length - String(number).length, 0);
|
||||||
return ret.substr(ret.length - length);
|
return '0'.repeat(zerosToAdd) + number;
|
||||||
|
} else {
|
||||||
|
return '0'.repeat(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the two input (let them be objects or arrays or just primitives) are equal
|
* Checks if the two input (let them be objects or arrays or just primitives) are equal
|
||||||
*/
|
*/
|
||||||
@ -186,7 +190,7 @@ export class Utils {
|
|||||||
gps.GPSDateStamp &&
|
gps.GPSDateStamp &&
|
||||||
gps.GPSTimeStamp) { //else use exif.gps.GPS*Stamp if available
|
gps.GPSTimeStamp) { //else use exif.gps.GPS*Stamp if available
|
||||||
//GPS timestamp is always UTC (+00:00)
|
//GPS timestamp is always UTC (+00:00)
|
||||||
UTCTimestamp = gps.GPSDateStamp.replaceAll(':', '-') + " " + gps.GPSTimeStamp.map((num: any) => Utils.zeroPad(num ,2)).join(':');
|
UTCTimestamp = gps.GPSDateStamp.replaceAll(':', '-') + " " + gps.GPSTimeStamp.map((num: any) => Utils.zeroPrefix(num ,2)).join(':');
|
||||||
}
|
}
|
||||||
if (UTCTimestamp && timestamp) {
|
if (UTCTimestamp && timestamp) {
|
||||||
//offset in minutes is the difference between gps timestamp and given timestamp
|
//offset in minutes is the difference between gps timestamp and given timestamp
|
||||||
@ -202,22 +206,13 @@ export class Utils {
|
|||||||
if (-720 <= offsetMinutes && offsetMinutes <= 840) {
|
if (-720 <= offsetMinutes && offsetMinutes <= 840) {
|
||||||
//valid offset is within -12 and +14 hrs (https://en.wikipedia.org/wiki/List_of_UTC_offsets)
|
//valid offset is within -12 and +14 hrs (https://en.wikipedia.org/wiki/List_of_UTC_offsets)
|
||||||
return (offsetMinutes < 0 ? "-" : "+") + //leading +/-
|
return (offsetMinutes < 0 ? "-" : "+") + //leading +/-
|
||||||
Utils.zeroPad(Math.trunc(Math.abs(offsetMinutes) / 60), 2) + ":" + //zeropadded hours and ':'
|
Utils.zeroPrefix(Math.trunc(Math.abs(offsetMinutes) / 60), 2) + ":" + //zeropadded hours and ':'
|
||||||
Utils.zeroPad((Math.abs(offsetMinutes) % 60), 2); //zeropadded minutes
|
Utils.zeroPrefix((Math.abs(offsetMinutes) % 60), 2); //zeropadded minutes
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static zeroPad(number: any, length: number): string {
|
|
||||||
if (!isNaN(number)) {
|
|
||||||
const zerosToAdd = Math.max(length - String(number).length, 0);
|
|
||||||
return '0'.repeat(zerosToAdd) + number;
|
|
||||||
} else {
|
|
||||||
return '0'.repeat(number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static getOffsetMinutes(offsetString: string) { //Convert offset string (+HH:MM or -HH:MM) into a minute value
|
static getOffsetMinutes(offsetString: string) { //Convert offset string (+HH:MM or -HH:MM) into a minute value
|
||||||
const regex = /^([+-](0[0-9]|1[0-4]):[0-5][0-9])$/; //checks if offset is between -14:00 and +14:00.
|
const regex = /^([+-](0[0-9]|1[0-4]):[0-5][0-9])$/; //checks if offset is between -14:00 and +14:00.
|
||||||
//-12:00 is the lowest valid UTC-offset, but we allow down to -14 for efficiency
|
//-12:00 is the lowest valid UTC-offset, but we allow down to -14 for efficiency
|
||||||
|
Loading…
Reference in New Issue
Block a user