Skip to content

Commit

Permalink
Merge pull request #41 from Shinsina/correct-dates-attempt-2
Browse files Browse the repository at this point in the history
See if timezone offset is available to set dayZero value
  • Loading branch information
Shinsina authored Apr 11, 2024
2 parents bbee93f + 39d6c5d commit 91df32e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/utils/determine-start-of-week-for-date-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ export default ({
object: Record<string, Array<string>>;
dateString: string;
}) => {
const d = new Date(`${String(dateString)} 19:00:00 GMT-05:00`);
const d = new Date(String(dateString));
const day = d.getDay();
const utcDateString = d.toUTCString();
if (day === 1 && !object[utcDateString]) {
const minutesAwayFromUTC = d.getTimezoneOffset();
const dayZero = minutesAwayFromUTC ? 1 : 0;
if (day === dayZero && !object[utcDateString]) {
object[utcDateString] = [utcDateString];
} else if (day !== 1) {
const distanceFromOne = day - 1;
} else if (day !== dayZero) {
const distanceFromOne = day - dayZero;
const dayOneOfWeek = new Date(
Number(d) - distanceFromOne * 86400000
).toUTCString();
Expand Down

0 comments on commit 91df32e

Please sign in to comment.