aluna-crypto / alunajs

Standardizing Crypto Trading APIs across multiple exchanges.
MIT License
0 stars 0 forks source link

Replace `moment` by `date-fns` #8

Closed arboleya closed 3 years ago

arboleya commented 3 years ago

https://date-fns.org/

Torres-ssf commented 3 years ago

Replaced momentjs for date-fns https://github.com/alunacrypto/aluna.js/pull/1/commits/5a6ab5dfa9dc28711a484b5780cac4ea79ebbf7b

hems commented 3 years ago

Replaced momentjs for date-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.

image

Torres-ssf commented 3 years ago

@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

arboleya commented 3 years ago

@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.

Torres-ssf commented 3 years ago

@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

arboleya commented 3 years ago

If that's the case, perhaps it's because the exchange gives the date in UTC already. Right?

Torres-ssf commented 3 years ago

@arboleya It seems so, "createdAt": "2021-02-08T14:15:15.345Z", If I'm not mistaken, the Z at the end indicates that, right?

arboleya commented 3 years ago

Ok, then we can remove the package entirely.

Just keep an eye in case we need it for some other exchange in the future.

Torres-ssf commented 3 years ago

Done https://github.com/alunacrypto/aluna.js/pull/1/commits/23f020a162b491c24e2fc47f258ca0370219be42

arboleya commented 3 years ago

Thank you.

Question: is it expected to have the date-fns mention on the .lock file even after removing the dependency?

Torres-ssf commented 3 years ago

Nope... I did forget to remove @type/date-fns Just removed as well

hems commented 3 years ago

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

brenopolanski commented 3 years ago

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 })
}