Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The weekly timetable is not responsive to another calander #24

Open
guy490 opened this issue Jun 22, 2020 · 0 comments
Open

The weekly timetable is not responsive to another calander #24

guy490 opened this issue Jun 22, 2020 · 0 comments

Comments

@guy490
Copy link

guy490 commented Jun 22, 2020

I have been used this perfect tool a few days ago and noticed that there is a problem with the "genDayOfWeek" utils function.

In my local calendar, we are counting the week from Sunday to Saturday and unfortunately, when I use the function "genTimeBlock" that uses the "genDayOfWeek" function, it does not count from "Sunday" and the "Sunday" that in my local calendar is the beginning of the week, the function count "Sunday" like it's in the next week, and not as the beginning of the week.

The source of the problem is in this row:

return new Date(2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00);
because it looks at a specific week in 2019, that is the 1st day of the month is on "Monday".

To solve it locally, I created my own function and changed the number of days to make it count the "Sunday" as the first day of the week.

My suggestion is to make this function more general by adding some "What is your first day of the week?"

Code of the functions:

const genDayOfWeek = (DayOfWeekString) => {
  /*
    DayOfWeekString : SUN, MON, TUE, WED, THU, FRI, SAT
      type : string
   */
  if (typeof DayOfWeekString !== 'string') {
    throw new Error(`genDayOfWeek got parameter type: ${typeof DayOfWeekString}, but string expected`);
  }
  const str2numberString = {
    'mon': '01',
    'tue': '02',
    'wed': '03',
    'thu': '04',
    'fri': '05',
    'sat': '06',
    'sun': '07',
    '월': '01',
    '화': '02',
    '수': '03',
    '목': '04',
    '금': '05',
    '토': '06',
  };

  return new Date(`2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00`);
};

const genTimeBlock = (dayOfWeek, hours = 0, minutes = 0) => {
  const date = genDayOfWeek(dayOfWeek);
  date.setHours(hours);
  if (minutes != null) {
    date.setMinutes(minutes);
  }
  return date;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant