mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 01:43:43 +00:00
remove date dependencies
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"axios": "^0.21.1",
|
||||
"date-fns": "^2.19.0",
|
||||
"date-fns": "^2.20.1",
|
||||
"framer-motion": "^4",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
import { addMinutes, format, parseISO } from 'date-fns';
|
||||
|
||||
export const timeFormat = 'HH:mm';
|
||||
export const timeFormatSeconds = 'HH:mm:ss';
|
||||
|
||||
// time string from miliseconds
|
||||
export const stringFromMillis = (
|
||||
ms,
|
||||
showSeconds = true,
|
||||
delim = ':',
|
||||
ifNull = '...'
|
||||
) => {
|
||||
if (ms === null) return ifNull;
|
||||
const showWith0 = (value) => (value < 10 ? `0${value}` : value);
|
||||
const hours = showWith0(Math.floor((ms / (1000 * 60 * 60)) % 60));
|
||||
const minutes = showWith0(Math.floor((ms / (1000 * 60)) % 60));
|
||||
const seconds = showWith0(Math.floor((ms / 1000) % 60));
|
||||
return showSeconds
|
||||
? `${parseInt(hours) ? `${hours}${delim}` : ''}${minutes}${delim}${seconds}`
|
||||
: `${parseInt(hours) ? `${hours}${delim}` : ''}${minutes}`;
|
||||
};
|
||||
|
||||
// millis to seconds
|
||||
export const millisToSeconds = (millis) => {
|
||||
return Math.floor(millis / 1000);
|
||||
};
|
||||
|
||||
// millis to minutes
|
||||
export const millisToMinutes = (millis) => {
|
||||
return Math.floor(millis / 60000);
|
||||
};
|
||||
|
||||
// make date with string
|
||||
export const timeToDate = (time) => {
|
||||
const today = new Date();
|
||||
return new Date(today.toDateString() + ' ' + time);
|
||||
return new Date(refDate.toDateString() + ' ' + time);
|
||||
};
|
||||
|
||||
// utility to parse and format
|
||||
export const dateToTime = (time) => {
|
||||
const fTime = parseISO(time, 1);
|
||||
return format(fTime, timeFormat);
|
||||
};
|
||||
|
||||
// small shorthand for adding delay and formatting date
|
||||
export const addAndFormat = (time, delay) => {
|
||||
const fTime = parseISO(time, 1);
|
||||
return format(addMinutes(fTime, delay), timeFormat);
|
||||
// timeStringToMillis
|
||||
export const timeStringToMillis = (string) => {
|
||||
let time = string.split(':');
|
||||
return time[0] * 3600000 + time[1] * 60000;
|
||||
};
|
||||
|
||||
+4
-4
@@ -4696,10 +4696,10 @@ data-urls@^2.0.0:
|
||||
whatwg-mimetype "^2.3.0"
|
||||
whatwg-url "^8.0.0"
|
||||
|
||||
date-fns@^2.19.0:
|
||||
version "2.19.0"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.19.0.tgz#65193348635a28d5d916c43ec7ce6fbd145059e1"
|
||||
integrity sha512-X3bf2iTPgCAQp9wvjOQytnf5vO5rESYRXlPIVcgSbtT5OTScPcsf9eZU+B/YIkKAtYr5WeCii58BgATrNitlWg==
|
||||
date-fns@^2.20.1:
|
||||
version "2.20.1"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.20.1.tgz#7e60b7035284a5f83e37500376e738d9f49ecfd3"
|
||||
integrity sha512-8P5M8Kxbnovd0zfvOs7ipkiVJ3/zZQ0F/nrBW4x5E+I0uAZVZ80h6CKd24fSXQ5TLK5hXMtI4yb2O5rEZdUt2A==
|
||||
|
||||
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
|
||||
version "2.6.9"
|
||||
|
||||
Reference in New Issue
Block a user