Initial commit
Load this up somewhere where I can setup CI/CD
This commit is contained in:
15
src/app/lib/ordinalDate.ts
Normal file
15
src/app/lib/ordinalDate.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
export const ordinalToDate = (ordinal: number | string): Date => {
|
||||
const year = parseInt(`20${ordinal.toString().substring(0, 2)}`);
|
||||
const day = parseInt(ordinal.toString().substring(2));
|
||||
const date = new Date(year, 0);
|
||||
date.setDate(day);
|
||||
return date;
|
||||
};
|
||||
|
||||
export const dateToOrdinal = (date: Date): number => {
|
||||
const start = new Date(date.getUTCFullYear(), 0, 0);
|
||||
const diff = date.getTime() - start.getTime();
|
||||
const day = `00${(Math.floor(diff / (1000 * 60 * 60 * 24)) + 1)}`;
|
||||
return parseInt(`${(`${date.getUTCFullYear()}`).substring(2)}${day.substring(day.length - 3)}`);
|
||||
};
|
||||
Reference in New Issue
Block a user