Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substituir o Moment.js pelo Luxon #7

Closed
lucashpmelo opened this issue Nov 29, 2022 · 0 comments
Closed

Substituir o Moment.js pelo Luxon #7

lucashpmelo opened this issue Nov 29, 2022 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@lucashpmelo
Copy link
Owner

Descrição

Hoje é usado a biblioteca moment para formatar a data do evento com o fuso horário correto, mas ela acaba sendo muito grande por causa de todos os seus arquivos de dados de horas, que para a API manifestação de destinatário acaba sendo desnecessário pois só é utilizado os fusos do Brasil.

Como o luxon utiliza a API de Internacionalização (Intl) presente no Node.js ele acaba sendo bem mais leve, por essa razão acho valido fazer a troca das bibliotecas.

Exemplo de código

const moment = require("moment-timezone");
const { DateTime } = require("luxon");

const timezones = [
  "America/Noronha",
  "America/Araguaina",
  "America/Bahia",
  "America/Belem",
  "America/Fortaleza",
  "America/Maceio",
  "America/Recife",
  "America/Sao_Paulo",
  "America/Boa_Vista",
  "America/Campo_Grande",
  "America/Cuiaba",
  "America/Manaus",
  "America/Porto_Velho",
  "America/Rio_Branco",
];
const format = "YYYY-MM-DD[T]HH:mm:ssZ";
const toFormat = "yyyy-MM-dd'T'HH:mm:ssZZ";
const resultado = {};

const m = moment();
const l = DateTime.now();

timezones.forEach((t) => {
  resultado[t] = {
    Moment: m.tz(t).format(format),
    Luxon: l.setZone(t).toFormat(toFormat),
  };
});

console.table(resultado);
// ┌──────────────────────┬─────────────────────────────┬─────────────────────────────┐
// │       (index)        │           Moment            │            Luxon            │
// ├──────────────────────┼─────────────────────────────┼─────────────────────────────┤
// │   America/Noronha    │ '2022-11-29T11:42:46-02:00' │ '2022-11-29T11:42:46-02:00' │
// │  America/Araguaina   │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │    America/Bahia     │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │    America/Belem     │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │  America/Fortaleza   │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │    America/Maceio    │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │    America/Recife    │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │  America/Sao_Paulo   │ '2022-11-29T10:42:46-03:00' │ '2022-11-29T10:42:46-03:00' │
// │  America/Boa_Vista   │ '2022-11-29T09:42:46-04:00' │ '2022-11-29T09:42:46-04:00' │
// │ America/Campo_Grande │ '2022-11-29T09:42:46-04:00' │ '2022-11-29T09:42:46-04:00' │
// │    America/Cuiaba    │ '2022-11-29T09:42:46-04:00' │ '2022-11-29T09:42:46-04:00' │
// │    America/Manaus    │ '2022-11-29T09:42:46-04:00' │ '2022-11-29T09:42:46-04:00' │
// │ America/Porto_Velho  │ '2022-11-29T09:42:46-04:00' │ '2022-11-29T09:42:46-04:00' │
// │  America/Rio_Branco  │ '2022-11-29T08:42:46-05:00' │ '2022-11-29T08:42:46-05:00' │
// └──────────────────────┴─────────────────────────────┴─────────────────────────────┘
@lucashpmelo lucashpmelo added the enhancement New feature or request label Nov 29, 2022
@lucashpmelo lucashpmelo added this to the 1.0 milestone Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant