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