mirror of
https://github.com/mue/mue.git
synced 2026-07-13 12:07:45 +02:00
refactor(modules): second part of moving files around, changing layout etc
This commit is contained in:
37
src/utils/date/index.js
Normal file
37
src/utils/date/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// todo: maybe move stuff
|
||||
/**
|
||||
* If the number is between 3 and 20, return the number with the suffix "th". Otherwise, return the
|
||||
* number with the suffix "st", "nd", "rd", or "th" depending on the last digit of the number
|
||||
* @param d - The day of the month.
|
||||
* @returns the day of the month with the appropriate suffix.
|
||||
*/
|
||||
export function nth(d) {
|
||||
if (d > 3 && d < 21) {
|
||||
return d + 'th';
|
||||
}
|
||||
|
||||
switch (d % 10) {
|
||||
case 1:
|
||||
return d + 'st';
|
||||
case 2:
|
||||
return d + 'nd';
|
||||
case 3:
|
||||
return d + 'rd';
|
||||
default:
|
||||
return d + 'th';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a date and a timezone and returns a new date object with the timezone applied.
|
||||
* @param date - The date you want to convert.
|
||||
* @param tz - The timezone you want to convert to.
|
||||
* @returns A new Date object with the timezone set to the timezone passed in.
|
||||
*/
|
||||
export function convertTimezone(date, tz) {
|
||||
return new Date(
|
||||
(typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', {
|
||||
timeZone: tz,
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user