Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

83
Vistas
Temporal js yearMonth.subtract return the same month

I am trying to use Temporal yearMonth.subtract but is not working. add is working as expected.

Demo: https://codesandbox.io/s/objective-knuth-20ov2?file=/src/index.js

import { Temporal } from "@js-temporal/polyfill";

const currentMonth = Temporal.Now.plainDate("gregory").toPlainYearMonth();

console.log("currentMonth", currentMonth.toString());
console.log("after", currentMonth.add({ months: 1 }).toString());
console.log("before", currentMonth.subtract({ months: 1 }).toString());
currentMonth 2021-12-01[u-ca=gregory] 
after 2022-01-01[u-ca=gregory] 
before 2021-12-01[u-ca=gregory] 
about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

The code in the OP ought to work as you expected, this is a bug in v0.2.0 of that polyfill. It seems like it will be fixed in the shortly upcoming v0.3.0.

about 4 years ago · Santiago Gelvez Denunciar

0

Applying the Temporal toPlainYearMonth method to currentMonth before the addition/subtraction operation is causing the problem.

This works as expected:

const currentMonth = Temporal.Now.plainDate("gregory");

console.log("currentMonth", currentMonth.toPlainYearMonth().toString());
console.log("after", currentMonth.add({ months: 1 }).toPlainYearMonth().toString());
console.log("before", currentMonth.subtract({ months: 1 }).toPlainYearMonth().toString());

Console output:

currentMonth 2021-12-01[u-ca=gregory] 
after 2022-01-01[u-ca=gregory] 
before 2021-11-01[u-ca=gregory] 
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda