|
| 1 | +// Copyright (C) 2018 Bloomberg LP. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-temporal-intl |
| 6 | +description: Addition across lunisolar leap months |
| 7 | +features: [Temporal] |
| 8 | +---*/ |
| 9 | + |
| 10 | +const chineseYearOffset = new Temporal.PlainDate(1, 1, 1, "chinese").year; |
| 11 | + |
| 12 | +// Adding years across Chinese leap month |
| 13 | +var date = Temporal.PlainDate.from({ |
| 14 | + year: 2000 + chineseYearOffset, |
| 15 | + monthCode: "M08", |
| 16 | + day: 2, |
| 17 | + calendar: "chinese" |
| 18 | +}); |
| 19 | +var added = date.add({ years: 1 }); |
| 20 | +assert.sameValue(added.day, date.day); |
| 21 | +assert.sameValue(added.monthCode, date.monthCode); |
| 22 | +assert.sameValue(added.year, date.year + 1); |
| 23 | + |
| 24 | +// Adding months across Chinese leap month |
| 25 | +var date = Temporal.PlainDate.from({ |
| 26 | + year: 2000 + chineseYearOffset, |
| 27 | + monthCode: "M08", |
| 28 | + day: 2, |
| 29 | + calendar: "chinese" |
| 30 | +}); |
| 31 | +var added = date.add({ months: 13 }); |
| 32 | +assert.sameValue(added.day, date.day); |
| 33 | +assert.sameValue(added.monthCode, date.monthCode); |
| 34 | +assert.sameValue(added.year, date.year + 1); |
| 35 | + |
| 36 | +// Adding months and years across Chinese leap month |
| 37 | +var date = Temporal.PlainDate.from({ |
| 38 | + year: 2001 + chineseYearOffset, |
| 39 | + monthCode: "M08", |
| 40 | + day: 2, |
| 41 | + calendar: "chinese" |
| 42 | +}); |
| 43 | +var added = date.add({ |
| 44 | + years: 1, |
| 45 | + months: 12 |
| 46 | +}); |
| 47 | +assert.sameValue(added.day, date.day); |
| 48 | +assert.sameValue(added.monthCode, date.monthCode); |
| 49 | +assert.sameValue(added.year, date.year + 2); |
0 commit comments