Skip to content

Commit

Permalink
chore(deps-dev): bump vitest from 2.1.8 to 3.0.3 (#3981)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump vitest from 2.1.8 to 3.0.3

Bumps [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) from 2.1.8 to 3.0.3.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v3.0.3/packages/vitest)

---
updated-dependencies:
- dependency-name: vitest
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* refactor(date): improve date parsing and handling in dateFromString function

* ci: update yarn.lock

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Olivier Savignac <1275666+sircharlo@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and sircharlo authored Jan 22, 2025
1 parent 2ff8975 commit 1689800
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 493 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"prettier": "^3.4.2",
"typescript": "~5.6.3",
"vitepress": "^1.6.3",
"vitest": "^2.1.8",
"vitest": "^3.0.3",
"vue-tsc": "^2.2.0"
},
"browserslist": [
Expand Down
10 changes: 5 additions & 5 deletions src/utils/__tests__/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ describe('getSpecificWeekday', () => {
const monday = getSpecificWeekday(date, 0);
expect(monday.getDay()).toBe(1);

const wednessday = getSpecificWeekday(date, 3);
expect(wednessday.getDay()).toBe(4);
const wed = getSpecificWeekday(date, 3);
expect(wed.getDay()).toBe(4);

const sunday = getSpecificWeekday(date, 6);
expect(sunday.getDay()).toBe(0);
const sun = getSpecificWeekday(date, 6);
expect(sun.getDay()).toBe(0);
});
});

Expand Down Expand Up @@ -122,7 +122,7 @@ describe('dateFromString', () => {
});

it('should reset the time to 00:00:00', () => {
const date = dateFromString(new Date().toISOString());
const date = dateFromString(new Date());
expect(date.getHours()).toBe(0);
expect(date.getMinutes()).toBe(0);
expect(date.getSeconds()).toBe(0);
Expand Down
52 changes: 46 additions & 6 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,54 @@ import { capitalize, pad } from 'src/utils/general';
*/
export const dateFromString = (lookupDate?: Date | string | undefined) => {
try {
const date = lookupDate ? new Date(lookupDate) : new Date();
date.setHours(0, 0, 0, 0);
return date;
let date: Date;

if (!lookupDate) {
// If no input, default to today's date
date = new Date();
} else if (lookupDate instanceof Date) {
// If it's already a Date object
date = new Date(lookupDate);
} else if (typeof lookupDate === 'string') {
// Handle ISO strings or other formats
if (!isNaN(Date.parse(lookupDate))) {
const isISO = lookupDate.includes('T');
if (isISO) {
date = new Date(lookupDate); // Parse ISO string directly
} else {
// Normalize separators for yyyy/mm/dd and yyyy.mm.dd
const normalizedDate = lookupDate.replace(/[.\-/]/g, '-');
const [year, month, day] = normalizedDate.split('-').map(Number);

if (
typeof year === 'number' &&
typeof month === 'number' &&
typeof day === 'number' &&
!isNaN(year) &&
!isNaN(month) &&
!isNaN(day)
) {
date = new Date(year, month - 1, day); // Create local date
} else {
throw new Error('Invalid date format');
}
}
} else {
throw new Error('Unsupported date format');
}
} else {
throw new Error('Unsupported input type');
}

// Return the date with time set to midnight
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
} catch (error) {
errorCatcher(error);
const date = new Date();
date.setHours(0, 0, 0, 0);
return date;

// Fallback: return today's date set to midnight
const fallbackDate = new Date();
fallbackDate.setHours(0, 0, 0, 0);
return fallbackDate;
}
};

Expand Down
Loading

0 comments on commit 1689800

Please sign in to comment.