Skip to content

Commit

Permalink
fix(dates): dynamic prefixed year characters
Browse files Browse the repository at this point in the history
We should be good until year 9999 now..
  • Loading branch information
Vexcited committed Jul 10, 2024
1 parent b99c628 commit dbe0968
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pronote/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const translateToPronoteWeekNumber = (dateToTranslate: Date, startDay: Da
const SHORT_DATE_RE = /^\d{2}\/\d{2}\/\d{4}$/;
const LONG_DATE_LONG_HOURS_RE = /^\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}$/;
const LONG_DATE_SHORT_HOURS_RE = /^\d{2}\/\d{2}\/\d{2} \d{2}h\d{2}$/;
const YEAR_FIRST_TWO_CHARS = new Date().getFullYear().toString().slice(0, 2);

/**
* Convert a date from Pronote API to a JS `Date`.
Expand All @@ -40,8 +41,7 @@ export const readPronoteApiDate = (formatted: string): Date => {
const [day, month, year] = date.split("/").map(Number);
const [hours, minutes] = time.split("h").map(Number);

// NOTE: Fix this when we're 2100, just saying.
const output = new Date(parseInt(`20${year}`), month - 1, day);
const output = new Date(parseInt(`${YEAR_FIRST_TWO_CHARS}${year}`), month - 1, day);
output.setHours(hours, minutes);
return output;
}
Expand Down

0 comments on commit dbe0968

Please sign in to comment.