remove dependency from luxon

This commit is contained in:
Neeraj Gupta 2022-03-06 13:40:10 +05:30
parent 85ad90a1f6
commit 483be815ee
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
4 changed files with 4317 additions and 5391 deletions

View file

@ -40,7 +40,6 @@
"jszip": "3.7.1",
"libsodium-wrappers": "^0.7.8",
"localforage": "^1.9.0",
"luxon": "^2.3.1",
"next": "^12.1.0",
"photoswipe": "file:./thirdparty/photoswipe",
"piexifjs": "^1.0.6",

View file

@ -8,7 +8,6 @@ import FormControl from 'react-bootstrap/FormControl';
import { Button, Col, Table } from 'react-bootstrap';
import { DeadCenter, GalleryContext } from 'pages/gallery';
import { User } from 'types/user';
import { DateTime } from 'luxon';
import {
shareCollection,
unshareCollection,
@ -31,6 +30,7 @@ import { handleSharingErrors } from 'utils/error';
import { sleep } from 'utils/common';
import { SelectStyles } from './Search/SelectStyle';
import CryptoWorker from 'utils/crypto';
import { getUnixTimeInMicroSecondsWithDelta } from 'utils/time';
interface Props {
show: boolean;
onHide: () => void;
@ -82,23 +82,23 @@ const expiryOptions = [
{ label: 'never', value: () => 0 },
{
label: 'after 1 hour',
value: () => DateTime.utc().plus({ hours: 1 }).toMillis() * 1000,
value: () => getUnixTimeInMicroSecondsWithDelta({ hours: 1 }),
},
{
label: 'after 1 day',
value: () => DateTime.utc().plus({ days: 1 }).toMillis() * 1000,
value: () => getUnixTimeInMicroSecondsWithDelta({ days: 1 }),
},
{
label: 'after 1 week',
value: () => DateTime.utc().plus({ days: 7 }).toMillis() * 1000,
value: () => getUnixTimeInMicroSecondsWithDelta({ days: 7 }),
},
{
label: 'after 1 month',
value: () => DateTime.utc().plus({ months: 1 }).toMillis() * 1000,
value: () => getUnixTimeInMicroSecondsWithDelta({ months: 1 }),
},
{
label: 'after 1 year',
value: () => DateTime.utc().plus({ years: 1 }).toMillis() * 1000,
value: () => getUnixTimeInMicroSecondsWithDelta({ years: 1 }),
},
];
@ -327,9 +327,13 @@ function CollectionShare(props: Props) {
if (validTill === 0) {
return 'never';
}
return DateTime.fromMillis(Math.round(validTill / 1000)).toLocaleString(
DateTime.DATETIME_MED
);
return new Date(validTill / 1000).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
});
};
const ShareeRow = ({ sharee, collectionUnshare }: ShareeProps) => (

View file

@ -1,3 +1,29 @@
export interface TimeDetla {
hours?: number;
days?: number;
months?: number;
years?: number;
}
export function getUnixTimeInMicroSecondsWithDelta(delta: TimeDetla): number {
let currentDate = new Date();
console.log(currentDate);
console.log(currentDate.getUTCMilliseconds());
if (delta?.hours) {
currentDate = _addHours(currentDate, delta.hours);
}
if (delta?.days) {
currentDate = _addDays(currentDate, delta.days);
}
if (delta?.months) {
currentDate = _addMonth(currentDate, delta.months);
}
if (delta?.years) {
currentDate = _addYears(currentDate, delta.years);
}
return currentDate.valueOf() * 1000;
}
export function getUnixTimeInMicroSeconds(dateTime: Date) {
if (!dateTime || isNaN(dateTime.getTime())) {
return null;
@ -9,3 +35,27 @@ export function getUnixTimeInMicroSeconds(dateTime: Date) {
return unixTime;
}
}
function _addDays(date: Date, days: number): Date {
const result = new Date(date);
result.setDate(date.getDate() + days);
return result;
}
function _addHours(date: Date, hours: number): Date {
const result = new Date(date);
result.setHours(date.getHours() + hours);
return result;
}
function _addMonth(date: Date, months: number) {
const result = new Date(date);
result.setMonth(date.getMonth() + months);
return result;
}
function _addYears(date: Date, years: number) {
const result = new Date(date);
result.setFullYear(date.getFullYear() + years);
return result;
}

9635
yarn.lock

File diff suppressed because it is too large Load diff