Skip to content

Commit

Permalink
feat: two weeks = 15 day span bug (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
thundermiracle committed Sep 26, 2022
1 parent c29571c commit 12bd847
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -14,7 +14,7 @@ Base URL: `https://jp-holidays.vercel.app`
| Parameter | Type | Required | Default | Description |
| ------------ | :-----: | :------: | :-----: | --------------------------------------------------------------------- |
| from | string || | start date <br /> \* required if offset is not set |
| to | string | | | end date <br /> \* will be from+14 days if not set |
| to | string | | | end date <br /> \* will be from+13 days if not set (2 weeks) |
| offset | string || | offset from today (exp: 4 days) <br /> \* required if from is not set |
| only_weekday | boolean | | false | only return holidays in weekdays |

Expand Down
6 changes: 3 additions & 3 deletions __test__/utils/edgeHelpers/getFromTo.spec.ts
Expand Up @@ -48,15 +48,15 @@ describe('getFromTo', () => {
const { data } = getFromTo(url);

expect(data?.from.format('YYYYMMDD')).toBe('20100101');
expect(data?.to.format('YYYYMMDD')).toBe('20100115');
expect(data?.to.format('YYYYMMDD')).toBe('20100114');
});

it('plus 2 weeks from from if to is before from', () => {
const url = 'https://example.com/holidays?from=20100101&to=20000101';
const { data } = getFromTo(url);

expect(data?.from.format('YYYYMMDD')).toBe('20100101');
expect(data?.to.format('YYYYMMDD')).toBe('20100115');
expect(data?.to.format('YYYYMMDD')).toBe('20100114');
});

it('parse from to correctly by from&to query parameters', () => {
Expand All @@ -72,6 +72,6 @@ describe('getFromTo', () => {
const { data } = getFromTo(url);

expect(data?.from.format('YYYYMMDD')).toBe('20220206');
expect(data?.to.format('YYYYMMDD')).toBe('20220220');
expect(data?.to.format('YYYYMMDD')).toBe('20220219');
});
});
3 changes: 2 additions & 1 deletion src/utils/edgeHelpers.ts
Expand Up @@ -70,7 +70,8 @@ export function getFromTo(url: string): {

// validate range
if (to == null || dayjs(to).isBefore(data.from)) {
data.to = data.from.add(14, 'day');
// 2 weeks
data.to = data.from.add(13, 'day');
}

return { data };
Expand Down

1 comment on commit 12bd847

@vercel
Copy link

@vercel vercel bot commented on 12bd847 Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.