Estoy tratando de usar Temporal yearMonth.subtract pero no funciona. add funciona como se esperaba.
Demostración: 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]El código en el OP debería funcionar como esperaba, este es un error en v0.2.0 de ese polyfill. Parece que se solucionará en la próxima v0.3.0.
Aplicar el método Temporal toPlainYearMonth a currentMonth antes de la operación de suma/resta está causando el problema.
Esto funciona como se esperaba:
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());Salida de la consola:
currentMonth 2021-12-01[u-ca=gregory] after 2022-01-01[u-ca=gregory] before 2021-11-01[u-ca=gregory]