mirror of
https://github.com/mue/mue.git
synced 2026-07-14 12:34:03 +02:00
refactor: move some date things about and separate, remove unnecessary files
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import variables from 'config/variables';
|
||||
import { useRef, useState, useEffect } from 'react';
|
||||
|
||||
import { nth, convertTimezone } from 'utils/date';
|
||||
import { appendNth, convertTimezone } from 'utils/date';
|
||||
import EventBus from 'utils/eventbus';
|
||||
import defaults from './options/default';
|
||||
|
||||
@@ -107,7 +107,7 @@ function Greeting() {
|
||||
if (birth.getDate() === now.getDate() && birth.getMonth() === now.getMonth()) {
|
||||
if (localStorage.getItem('birthdayage') === 'true' && calculateAge(birth) !== 0) {
|
||||
const text = variables.getMessage('widgets.greeting.birthday').split(' ');
|
||||
message = `${text[0]} ${nth(calculateAge(birth))} ${text[1]}`;
|
||||
message = `${text[0]} ${appendNth(calculateAge(birth))} ${text[1]}`;
|
||||
} else {
|
||||
message = variables.getMessage('widgets.greeting.birthday');
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import variables from 'config/variables';
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
|
||||
import { nth, convertTimezone } from 'utils/date';
|
||||
import { appendNth, convertTimezone } from 'utils/date';
|
||||
import EventBus from 'utils/eventbus';
|
||||
import defaults from './options/default';
|
||||
|
||||
@@ -98,7 +98,7 @@ const DateWidget = () => {
|
||||
|
||||
const datenth =
|
||||
localStorage.getItem('datenth') === 'true'
|
||||
? nth(currentDate.getDate())
|
||||
? appendNth(currentDate.getDate())
|
||||
: currentDate.getDate();
|
||||
|
||||
const dateDay =
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
.mobile {
|
||||
.navbar {
|
||||
flex-flow: column;
|
||||
}
|
||||
|
||||
.searchComponents {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#modal {
|
||||
// fill screen
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.modalSidebar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
@import 'variables';
|
||||
@import 'toast';
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
13
src/utils/date/convertTimezone.js
Normal file
13
src/utils/date/convertTimezone.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
22
src/utils/date/getNth.js
Normal file
22
src/utils/date/getNth.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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 appendNth(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';
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,4 @@
|
||||
// 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';
|
||||
}
|
||||
import { convertTimezone } from './convertTimezone';
|
||||
import { getNth } from './getNth';
|
||||
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
export { convertTimezone, getNth };
|
||||
|
||||
Reference in New Issue
Block a user