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

fix: ensure date-fns#parse is called with a string #111

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

lebalz
Copy link
Contributor

@lebalz lebalz commented Apr 3, 2024

Currently, the webuntis api of our school returns the school year as number. This creates an error when calling parse(20240403, 'yyyyMMdd', new Date()) (from date-fns).

The proposed fix ensures the parse function of date-fns is called always with a string by redefining the parse function (which is really only a simple wrapper that transforms dateStr to a string).:

import { parse as fnsParse, /*...*/ type ParseOptions } from 'date-fns';
// ...
const parse = <DateType extends Date>(
    dateStr: string | number,
    formatStr: string,
    referenceDate: DateType | number | string,
    options?: ParseOptions,
) => {
    return fnsParse(`${dateStr}`, formatStr, referenceDate, options);
};
// ...

Thanks for having a look and btw. i like your project! Thanks :)

@TheNoim TheNoim merged commit 7ec4141 into SchoolUtils:master Apr 6, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants