forked from nation3/mobile-passport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(apple): add dateutils class (nation3#76)
- Loading branch information
1 parent
df21a4d
commit 293fc43
Showing
2 changed files
with
27 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
/** | ||
* Calculates a Date's epoch timestamp in seconds. Rounds to the nearest integer to avoid decimals. | ||
*/ | ||
export function getTimeInSeconds(date: Date): number { | ||
console.log('getTimeInSeconds') | ||
const timeInMilliseconds: number = date.getTime() | ||
const timeInSeconds: number = timeInMilliseconds / 1000 | ||
const timeInSecondsRoundedToNearestInteger: number = Math.round(timeInSeconds) | ||
return timeInSecondsRoundedToNearestInteger | ||
} | ||
export class DateUtils { | ||
|
||
/** | ||
* Calculates a Date's epoch timestamp in seconds. Rounds to the nearest integer to avoid decimals. | ||
*/ | ||
static getTimeInSeconds(date: Date): number { | ||
console.log('getTimeInSeconds') | ||
const timeInMilliseconds: number = date.getTime() | ||
const timeInSeconds: number = timeInMilliseconds / 1000 | ||
const timeInSecondsRoundedToNearestInteger: number = Math.round(timeInSeconds) | ||
return timeInSecondsRoundedToNearestInteger | ||
} | ||
|
||
/** | ||
* Converts from an epoch timestamp (e.g. 1662889385) to Date. | ||
* | ||
* @param timeInSeconds The UNIX timestamp in seconds, e.g. 1662889385. | ||
*/ | ||
export function getDate(timeInSeconds: number): Date { | ||
console.log('getDate') | ||
const timeInMilliseconds: number = timeInSeconds * 1000 | ||
const date: Date = new Date(timeInMilliseconds) | ||
return date | ||
/** | ||
* Converts from an epoch timestamp (e.g. 1662889385) to Date. | ||
* | ||
* @param timeInSeconds The UNIX timestamp in seconds, e.g. 1662889385. | ||
*/ | ||
static getDate(timeInSeconds: number): Date { | ||
console.log('getDate') | ||
const timeInMilliseconds: number = timeInSeconds * 1000 | ||
const date: Date = new Date(timeInMilliseconds) | ||
return date | ||
} | ||
} |