Closed arboleya closed 3 years ago
Replaced momentjs
for date-fns
https://github.com/alunacrypto/aluna.js/pull/1/commits/5a6ab5dfa9dc28711a484b5780cac4ea79ebbf7b
Replaced
momentjs
fordate-fns
5a6ab5d
after your commit here it looks like you don't need moment or date-fns anymore and you could remove date-fns from package.json all together.
@hems Yes, you're right. I also noticed that. It seems new Date()
already does the trick. I left date-fns
just in case we might need it later on. Maybe we can remove it for now
@Torres-ssf The problem is that new Date()
won't convert the time to UTC, right?
I just searched for it, and here's how it seems to be done with date-fns
:
It needs a careful look and testing.
@arboleya I tested at my side and both new Date()
and moment's utc
method had the exact same output. Do you think this output can be different when running at the server? I'm going to try this approach
If that's the case, perhaps it's because the exchange gives the date in UTC already. Right?
@arboleya It seems so, "createdAt": "2021-02-08T14:15:15.345Z",
If I'm not mistaken, the Z at the end indicates that, right?
Ok, then we can remove the package entirely.
Just keep an eye in case we need it for some other exchange in the future.
Thank you.
Question: is it expected to have the date-fns
mention on the .lock
file even after removing the dependency?
Nope...
I did forget to remove @type/date-fns
Just removed as well
I think the .toISOString()
always return the date with UTC and ready to be saved on MongoDB ?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
I have an example for date-fns
working with UTC
, if that's the case:
import { parseISO } from 'date-fns'
import { format as formatDate, utcToZonedTime } from 'date-fns-tz'
export const formatDateTimezone = (
date: string,
format: string,
timeZone = 'UTC'
) => {
const parsedDate = parseISO(date)
return formatDate(utcToZonedTime(parsedDate, timeZone), format, { timeZone })
}
https://date-fns.org/