Best Python code snippet using localstack_python
calendar-date-until.js
Source:calendar-date-until.js  
1// Copyright 2021 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --harmony-temporal5// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateuntil6let cal = new Temporal.Calendar("iso8601");7// Test throw8[ "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" ]9.forEach(function(largestUnit) {10  assertThrows(() => cal.dateUntil("2021-07-16", "2021-07-17",11        {largestUnit}), RangeError,12      "Invalid unit argument for Temporal.Calendar.prototype.dateUntil() "+13      "'largestUnit'");14});15assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16").toJSON());16assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17").toJSON());17assertEquals("P32D", cal.dateUntil("2021-07-16", "2021-08-17").toJSON());18assertEquals("P62D", cal.dateUntil("2021-07-16", "2021-09-16").toJSON());19assertEquals("P365D", cal.dateUntil("2021-07-16", "2022-07-16").toJSON());20assertEquals("P3652D", cal.dateUntil("2021-07-16", "2031-07-16").toJSON());21assertEquals("-P1D", cal.dateUntil("2021-07-17", "2021-07-16").toJSON());22assertEquals("-P32D", cal.dateUntil("2021-08-17", "2021-07-16").toJSON());23assertEquals("-P62D", cal.dateUntil("2021-09-16", "2021-07-16").toJSON());24assertEquals("-P365D", cal.dateUntil("2022-07-16", "2021-07-16").toJSON());25assertEquals("-P3652D", cal.dateUntil("2031-07-16", "2021-07-16").toJSON());26["day", "days"].forEach(function(largestUnit) {27  let opt = {largestUnit};28  assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());29  assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());30  assertEquals("P32D", cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());31  assertEquals("P62D", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());32  assertEquals("P365D",33      cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());34  assertEquals("P3652D"35      ,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());36  assertEquals("-P1D",37      cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());38  assertEquals("-P32D",39      cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());40  assertEquals("-P62D",41      cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());42  assertEquals("-P365D",43      cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());44  assertEquals("-P3652D",45      cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());46});47["week", "weeks"].forEach(function(largestUnit) {48  let opt = {largestUnit};49  assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());50  assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());51  assertEquals("P1W", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());52  assertEquals("P4W4D",53      cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());54  assertEquals("P4W", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());55  assertEquals("P8W6D",56      cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());57  assertEquals("P52W1D",58      cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());59  assertEquals("P521W5D"60      ,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());61  assertEquals("-P1D",62      cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());63  assertEquals("-P4W4D",64      cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());65  assertEquals("-P4W",66      cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());67  assertEquals("-P8W6D",68      cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());69  assertEquals("-P52W1D",70      cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());71  assertEquals("-P521W5D",72      cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());73});74["month", "months"].forEach(function(largestUnit) {75  let opt = {largestUnit};76  assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());77  assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());78  assertEquals("P7D", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());79  assertEquals("P1M", cal.dateUntil("2021-07-16", "2021-08-16", opt).toJSON());80  assertEquals("P1M", cal.dateUntil("2020-12-16", "2021-01-16", opt).toJSON());81  assertEquals("P1M", cal.dateUntil("2021-01-05", "2021-02-05", opt).toJSON());82  assertEquals("P2M", cal.dateUntil("2021-01-07", "2021-03-07", opt).toJSON());83  assertEquals("P1M1D",84      cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());85  assertEquals("P28D", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());86  assertEquals("P2M", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());87  assertEquals("P12M",88      cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());89  assertEquals("P120M"90      ,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());91  assertEquals("-P1D",92      cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());93  assertEquals("-P1M1D",94      cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());95  assertEquals("-P28D",96      cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());97  assertEquals("-P1M",98      cal.dateUntil("2021-08-16", "2021-07-16", opt).toJSON());99  assertEquals("-P1M3D",100      cal.dateUntil("2021-08-16", "2021-07-13", opt).toJSON());101  assertEquals("-P2M",102      cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());103  assertEquals("-P2M5D",104      cal.dateUntil("2021-09-21", "2021-07-16", opt).toJSON());105  assertEquals("-P12M",106      cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());107  assertEquals("-P12M1D",108      cal.dateUntil("2022-07-17", "2021-07-16", opt).toJSON());109  assertEquals("-P120M",110      cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());111});112["year", "years"].forEach(function(largestUnit) {113  let opt = {largestUnit};114  assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());115  assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());116  assertEquals("P7D", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());117  assertEquals("P1M", cal.dateUntil("2021-07-16", "2021-08-16", opt).toJSON());118  assertEquals("P1M", cal.dateUntil("2020-12-16", "2021-01-16", opt).toJSON());119  assertEquals("P1M", cal.dateUntil("2021-01-05", "2021-02-05", opt).toJSON());120  assertEquals("P2M", cal.dateUntil("2021-01-07", "2021-03-07", opt).toJSON());121  assertEquals("P1M1D", cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());122  assertEquals("P28D", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());123  assertEquals("P2M", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());124  assertEquals("P1Y",125      cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());126  assertEquals("P1Y3D",127      cal.dateUntil("2021-07-16", "2022-07-19", opt).toJSON());128  assertEquals("P1Y2M3D",129      cal.dateUntil("2021-07-16", "2022-09-19", opt).toJSON());130  assertEquals("P10Y",131      cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());132  assertEquals("P10Y5M",133      cal.dateUntil("2021-07-16", "2031-12-16", opt).toJSON());134  assertEquals("P23Y7M",135      cal.dateUntil("1997-12-16", "2021-07-16", opt).toJSON());136  assertEquals("P24Y",137      cal.dateUntil("1997-07-16", "2021-07-16", opt).toJSON());138  assertEquals("P23Y11M29D",139      cal.dateUntil("1997-07-16", "2021-07-15", opt).toJSON());140  assertEquals("P23Y11M30D",141      cal.dateUntil("1997-06-16", "2021-06-15", opt).toJSON());142  assertEquals("P60Y1M",143      cal.dateUntil("1960-02-16", "2020-03-16", opt).toJSON());144  assertEquals("P61Y27D",145      cal.dateUntil("1960-02-16", "2021-03-15", opt).toJSON());146  assertEquals("P60Y28D",147      cal.dateUntil("1960-02-16", "2020-03-15", opt).toJSON());148  assertEquals("P3M16D",149      cal.dateUntil("2021-03-30", "2021-07-16", opt).toJSON());150  assertEquals("P1Y3M16D",151      cal.dateUntil("2020-03-30", "2021-07-16", opt).toJSON());152  assertEquals("P61Y3M16D",153      cal.dateUntil("1960-03-30", "2021-07-16", opt).toJSON());154  assertEquals("P1Y6M16D",155      cal.dateUntil("2019-12-30", "2021-07-16", opt).toJSON());156  assertEquals("P6M16D",157      cal.dateUntil("2020-12-30", "2021-07-16", opt).toJSON());158  assertEquals("P23Y6M16D",159      cal.dateUntil("1997-12-30", "2021-07-16", opt).toJSON());160  assertEquals("P2019Y6M21D",161      cal.dateUntil("0001-12-25", "2021-07-16", opt).toJSON());162  assertEquals("P1Y2M5D",163      cal.dateUntil("2019-12-30", "2021-03-05", opt).toJSON());164  assertEquals("-P1D",165      cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());166  assertEquals("-P1M1D",167      cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());168  assertEquals("-P28D",169      cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());170  assertEquals("-P1M",171      cal.dateUntil("2021-08-16", "2021-07-16", opt).toJSON());172  assertEquals("-P1M3D",173      cal.dateUntil("2021-08-16", "2021-07-13", opt).toJSON());174  assertEquals("-P2M",175      cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());176  assertEquals("-P2M5D",177      cal.dateUntil("2021-09-21", "2021-07-16", opt).toJSON());178  assertEquals("-P1Y",179      cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());180  assertEquals("-P1Y1D",181      cal.dateUntil("2022-07-17", "2021-07-16", opt).toJSON());182  assertEquals("-P1Y3M1D",183      cal.dateUntil("2022-10-17", "2021-07-16", opt).toJSON());184  assertEquals("-P10Y",185      cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());186  assertEquals("-P10Y11M",187      cal.dateUntil("2032-07-16", "2021-08-16", opt).toJSON());188  assertEquals("-P10Y5M",189      cal.dateUntil("2031-12-16", "2021-07-16", opt).toJSON());190  assertEquals("-P13Y7M",191      cal.dateUntil("2011-07-16", "1997-12-16", opt).toJSON());192  assertEquals("-P24Y",193      cal.dateUntil("2021-07-16", "1997-07-16", opt).toJSON());194  assertEquals("-P23Y11M30D",195      cal.dateUntil("2021-07-15", "1997-07-16", opt).toJSON());196  assertEquals("-P23Y11M29D",197      cal.dateUntil("2021-06-15", "1997-06-16", opt).toJSON());198  assertEquals("-P60Y1M",199      cal.dateUntil("2020-03-16", "1960-02-16", opt).toJSON());200  assertEquals("-P61Y28D",201      cal.dateUntil("2021-03-15", "1960-02-16", opt).toJSON());202  assertEquals("-P60Y28D",203      cal.dateUntil("2020-03-15", "1960-02-16", opt).toJSON());204  assertEquals("-P61Y3M17D",205      cal.dateUntil("2021-07-16", "1960-03-30", opt).toJSON());206  assertEquals("-P2019Y6M22D",207      cal.dateUntil("2021-07-16", "0001-12-25", opt).toJSON());208  assertEquals("-P23Y6M17D",209      cal.dateUntil("2021-07-16", "1997-12-30", opt).toJSON());...duration-to-json.js
Source:duration-to-json.js  
1// Copyright 2021 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --harmony-temporal5assertEquals("PT0S", (new Temporal.Duration()).toJSON());6assertEquals("P1Y", (new Temporal.Duration(1)).toJSON());7assertEquals("-P1Y", (new Temporal.Duration(-1)).toJSON());8assertEquals("P1234567890Y", (new Temporal.Duration(1234567890)).toJSON());9assertEquals("-P1234567890Y", (new Temporal.Duration(-1234567890)).toJSON());10assertEquals("P1Y2M", (new Temporal.Duration(1, 2)).toJSON());11assertEquals("-P1Y2M", (new Temporal.Duration(-1, -2)).toJSON());12assertEquals("P2M", (new Temporal.Duration(0, 2)).toJSON());13assertEquals("-P2M", (new Temporal.Duration(0,-2)).toJSON());14assertEquals("P1234567890M", (new Temporal.Duration(0, 1234567890)).toJSON());15assertEquals("-P1234567890M", (new Temporal.Duration(0,-1234567890)).toJSON());16assertEquals("P1Y2M3W", (new Temporal.Duration(1, 2, 3)).toJSON());17assertEquals("-P1Y2M3W", (new Temporal.Duration(-1, -2, -3)).toJSON());18assertEquals("P3W", (new Temporal.Duration(0, 0, 3)).toJSON());19assertEquals("-P3W", (new Temporal.Duration(0, 0, -3)).toJSON());20assertEquals("P1Y3W", (new Temporal.Duration(1, 0, 3)).toJSON());21assertEquals("-P1Y3W", (new Temporal.Duration(-1, 0, -3)).toJSON());22assertEquals("P2M3W", (new Temporal.Duration(0, 2, 3)).toJSON());23assertEquals("-P2M3W", (new Temporal.Duration(0, -2, -3)).toJSON());24assertEquals("P1234567890W",25    (new Temporal.Duration(0, 0, 1234567890)).toJSON());26assertEquals("-P1234567890W",27    (new Temporal.Duration(0, 0, -1234567890)).toJSON());28assertEquals("P1Y2M3W4D", (new Temporal.Duration(1, 2, 3, 4)).toJSON());29assertEquals("-P1Y2M3W4D", (new Temporal.Duration(-1, -2, -3, -4)).toJSON());30assertEquals("P1234567890D",31    (new Temporal.Duration(0, 0, 0, 1234567890)).toJSON());32assertEquals("-P1234567890D",33    (new Temporal.Duration(0, 0, 0, -1234567890)).toJSON());34assertEquals("P4D", (new Temporal.Duration(0, 0, 0, 4)).toJSON());35assertEquals("-P4D", (new Temporal.Duration(0, 0, 0, -4)).toJSON());36assertEquals("P1Y4D", (new Temporal.Duration(1, 0, 0, 4)).toJSON());37assertEquals("-P1Y4D", (new Temporal.Duration(-1, 0, 0, -4)).toJSON());38assertEquals("P2M4D", (new Temporal.Duration(0, 2, 0, 4)).toJSON());39assertEquals("-P2M4D", (new Temporal.Duration(0, -2, 0, -4)).toJSON());40assertEquals("P3W4D", (new Temporal.Duration(0, 0, 3, 4)).toJSON());41assertEquals("-P3W4D", (new Temporal.Duration(0, 0, -3, -4)).toJSON());42assertEquals("PT5H", (new Temporal.Duration(0, 0, 0, 0, 5)).toJSON());43assertEquals("-PT5H", (new Temporal.Duration(0, 0, 0, 0, -5)).toJSON());44assertEquals("P1YT5H", (new Temporal.Duration(1, 0, 0, 0, 5)).toJSON());45assertEquals("-P1YT5H", (new Temporal.Duration(-1, 0, 0, 0, -5)).toJSON());46assertEquals("P2MT5H", (new Temporal.Duration(0, 2, 0, 0, 5)).toJSON());47assertEquals("-P2MT5H", (new Temporal.Duration(0, -2, 0, 0, -5)).toJSON());48assertEquals("PT6M", (new Temporal.Duration(0, 0, 0, 0, 0, 6)).toJSON());49assertEquals("-PT6M", (new Temporal.Duration(0, 0, 0, 0, 0, -6)).toJSON());50assertEquals("PT5H6M", (new Temporal.Duration(0, 0, 0, 0, 5, 6)).toJSON());51assertEquals("-PT5H6M", (new Temporal.Duration(0, 0, 0, 0, -5, -6)).toJSON());52assertEquals("P3WT6M", (new Temporal.Duration(0, 0, 3, 0, 0, 6)).toJSON());53assertEquals("-P3WT6M", (new Temporal.Duration(0, 0, -3, 0, 0, -6)).toJSON());54assertEquals("P4DT6M", (new Temporal.Duration(0, 0, 0, 4, 0, 6)).toJSON());55assertEquals("-P4DT6M", (new Temporal.Duration(0, 0, 0, -4, 0, -6)).toJSON());56assertEquals("PT7S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, 7)).toJSON());57assertEquals("-PT7S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, -7)).toJSON());58assertEquals("PT5H7S", (new Temporal.Duration(0, 0, 0, 0, 5, 0, 7)).toJSON());59assertEquals("-PT5H7S",60    (new Temporal.Duration(0, 0, 0, 0, -5, 0, -7)).toJSON());61assertEquals("PT6M7S", (new Temporal.Duration(0, 0, 0, 0, 0, 6, 7)).toJSON());62assertEquals("-PT6M7S",63    (new Temporal.Duration(0, 0, 0, 0, 0, -6, -7)).toJSON());64assertEquals("PT5H6M7S", (new Temporal.Duration(0, 0, 0, 0, 5, 6, 7)).toJSON());65assertEquals("-PT5H6M7S",66    (new Temporal.Duration(0, 0, 0, 0, -5, -6, -7)).toJSON());67assertEquals("P1YT5H6M7S",68    (new Temporal.Duration(1, 0, 0, 0, 5, 6, 7)).toJSON());69assertEquals("-P1YT5H6M7S",70    (new Temporal.Duration(-1, 0, 0, 0, -5, -6, -7)).toJSON());71assertEquals("PT0.008S",72    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 8)).toJSON());73assertEquals("-PT0.008S",74    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -8)).toJSON());75assertEquals("PT0.08S",76    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 80)).toJSON());77assertEquals("-PT0.08S",78    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -80)).toJSON());79assertEquals("PT0.087S",80    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 87)).toJSON());81assertEquals("-PT0.087S",82    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -87)).toJSON());83assertEquals("PT0.876S",84    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 876)).toJSON());85assertEquals("-PT0.876S",86    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -876)).toJSON());87assertEquals("PT876.543S",88    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 876543)).toJSON());89assertEquals("-PT876.543S",90    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -876543)).toJSON());91assertEquals("PT0.000009S",92    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 9)).toJSON());93assertEquals("-PT0.000009S",94    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -9)).toJSON());95assertEquals("PT0.00009S",96    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 90)).toJSON());97assertEquals("-PT0.00009S",98    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -90)).toJSON());99assertEquals("PT0.000098S",100    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 98)).toJSON());101assertEquals("-PT0.000098S",102    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -98)).toJSON());103assertEquals("PT0.0009S",104    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 900)).toJSON());105assertEquals("-PT0.0009S",106    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -900)).toJSON());107assertEquals("PT0.000987S",108    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987)).toJSON());109assertEquals("-PT0.000987S",110    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987)).toJSON());111assertEquals("PT0.987654S",112    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987654)).toJSON());113assertEquals("-PT0.987654S",114    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987654)).toJSON());115assertEquals("PT987.654321S",116    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987654321)).toJSON());117assertEquals("-PT987.654321S",118    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987654321)).toJSON());119assertEquals("PT0.000000001S",120    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)).toJSON());121assertEquals("-PT0.000000001S",122    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -1)).toJSON());123assertEquals("PT0.00000001S",124    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 10)).toJSON());125assertEquals("-PT0.00000001S",126    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -10)).toJSON());127assertEquals("PT0.000000012S",128    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 12)).toJSON());129assertEquals("-PT0.000000012S",130    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -12)).toJSON());131assertEquals("PT0.0000001S",132    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 100)).toJSON());133assertEquals("-PT0.0000001S",134    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -100)).toJSON());135assertEquals("PT0.000000123S",136    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123)).toJSON());137assertEquals("-PT0.000000123S",138    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123)).toJSON());139assertEquals("PT0.000123456S",140    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123456)).toJSON());141assertEquals("-PT0.000123456S",142    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123456)).toJSON());143assertEquals("PT0.123456789S",144    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123456789)).toJSON());145assertEquals("-PT0.123456789S",146    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123456789)).toJSON());147assertEquals("PT1.234567891S",148    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 1234567891)).toJSON());149assertEquals("-PT1.234567891S",150    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -1234567891)).toJSON());151assertEquals("PT4.003002001S",152    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 1)).toJSON());153assertEquals("-PT4.003002001S",154    (new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -1)).toJSON());155assertEquals("PT4.003092001S",156    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 90001)).toJSON());157assertEquals("-PT4.003092001S",158    (new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -90001)).toJSON());159assertEquals("PT4.093082001S",160    (new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 90080001)).toJSON());161assertEquals("-PT4.093082001S",162    (new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -90080001)).toJSON());163assertEquals("P1Y2M3W4DT5H6M7.008009001S",164    (new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 1)).toJSON());165assertEquals("-P1Y2M3W4DT5H6M7.008009001S",166    (new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -1)).toJSON());167assertEquals("P1234Y2345M3456W4567DT5678H6789M7890.890901123S",168    (new Temporal.Duration(1234, 2345, 3456, 4567, 5678, 6789, 7890,169                           890, 901, 123)).toJSON());170assertEquals("-P1234Y2345M3456W4567DT5678H6789M7890.890901123S",171    (new Temporal.Duration(-1234, -2345, -3456, -4567, -5678, -6789, -7890,...test_toJSON.py
Source:test_toJSON.py  
1def WebIDLTest(parser, harness):2    threw = False3    try:4        parser.parse(5            """6            interface Test {7              object toJSON();8            };9            """10        )11        results = parser.finish()12    except:13        threw = True14    harness.ok(not threw, "Should allow a toJSON method.")15    parser = parser.reset()16    threw = False17    try:18        parser.parse(19            """20            interface Test {21              object toJSON(object arg);22              object toJSON(long arg);23            };24            """25        )26        results = parser.finish()27    except:28        threw = True29    harness.ok(threw, "Should not allow overloads of a toJSON method.")30    parser = parser.reset()31    threw = False32    try:33        parser.parse(34            """35            interface Test {36              object toJSON(object arg);37            };38            """39        )40        results = parser.finish()41    except:42        threw = True43    harness.ok(threw, "Should not allow a toJSON method with arguments.")44    parser = parser.reset()45    threw = False46    try:47        parser.parse(48            """49            interface Test {50              long toJSON();51            };52            """53        )54        results = parser.finish()55    except:56        threw = True57    harness.ok(not threw, "Should allow a toJSON method with 'long' as return type.")58    parser = parser.reset()59    threw = False60    try:61        parser.parse(62            """63            interface Test {64              [Default] object toJSON();65            };66            """67        )68        results = parser.finish()69    except:70        threw = True71    harness.ok(72        not threw, "Should allow a default toJSON method with 'object' as return type."73    )74    parser = parser.reset()75    threw = False76    try:77        parser.parse(78            """79            interface Test {80              [Default] long toJSON();81            };82            """83        )84        results = parser.finish()85    except:86        threw = True87    harness.ok(88        threw,89        "Should not allow a default toJSON method with non-'object' as return type.",90    )91    JsonTypes = [92        "byte",93        "octet",94        "short",95        "unsigned short",96        "long",97        "unsigned long",98        "long long",99        "unsigned long long",100        "float",101        "unrestricted float",102        "double",103        "unrestricted double",104        "boolean",105        "DOMString",106        "ByteString",107        "UTF8String",108        "USVString",109        "Enum",110        "InterfaceWithToJSON",111        "object",112    ]113    nonJsonTypes = [114        "InterfaceWithoutToJSON",115        "any",116        "Int8Array",117        "Int16Array",118        "Int32Array",119        "Uint8Array",120        "Uint16Array",121        "Uint32Array",122        "Uint8ClampedArray",123        "Float32Array",124        "Float64Array",125        "ArrayBuffer",126    ]127    def doTest(testIDL, shouldThrow, description):128        p = parser.reset()129        threw = False130        try:131            p.parse(132                testIDL133                + """134                enum Enum { "a", "b", "c" };135                interface InterfaceWithToJSON { long toJSON(); };136                interface InterfaceWithoutToJSON {};137                """138            )139            p.finish()140        except Exception as x:141            threw = True142            harness.ok(x.message == "toJSON method has non-JSON return type", x)143        harness.check(threw, shouldThrow, description)144    for type in JsonTypes:145        doTest(146            "interface Test { %s toJSON(); };" % type,147            False,148            "%s should be a JSON type" % type,149        )150        doTest(151            "interface Test { sequence<%s> toJSON(); };" % type,152            False,153            "sequence<%s> should be a JSON type" % type,154        )155        doTest(156            "dictionary Foo { %s foo; }; " "interface Test { Foo toJSON(); }; " % type,157            False,158            "dictionary containing only JSON type (%s) should be a JSON type" % type,159        )160        doTest(161            "dictionary Foo { %s foo; }; dictionary Bar : Foo { }; "162            "interface Test { Bar toJSON(); }; " % type,163            False,164            "dictionary whose ancestors only contain JSON types should be a JSON type",165        )166        doTest(167            "dictionary Foo { any foo; }; dictionary Bar : Foo { %s bar; };"168            "interface Test { Bar toJSON(); };" % type,169            True,170            "dictionary whose ancestors contain non-JSON types should not be a JSON type",171        )172        doTest(173            "interface Test { record<DOMString, %s> toJSON(); };" % type,174            False,175            "record<DOMString, %s> should be a JSON type" % type,176        )177        doTest(178            "interface Test { record<ByteString, %s> toJSON(); };" % type,179            False,180            "record<ByteString, %s> should be a JSON type" % type,181        )182        doTest(183            "interface Test { record<UTF8String, %s> toJSON(); };" % type,184            False,185            "record<UTF8String, %s> should be a JSON type" % type,186        )187        doTest(188            "interface Test { record<USVString, %s> toJSON(); };" % type,189            False,190            "record<USVString, %s> should be a JSON type" % type,191        )192        otherUnionType = "Foo" if type != "object" else "long"193        doTest(194            "interface Foo { object toJSON(); };"195            "interface Test { (%s or %s) toJSON(); };" % (otherUnionType, type),196            False,197            "union containing only JSON types (%s or %s) should be a JSON type"198            % (otherUnionType, type),199        )200        doTest(201            "interface test { %s? toJSON(); };" % type,202            False,203            "Nullable type (%s) should be a JSON type" % type,204        )205        doTest(206            "interface Foo : InterfaceWithoutToJSON { %s toJSON(); };"207            "interface Test { Foo toJSON(); };" % type,208            False,209            "interface with toJSON should be a JSON type",210        )211    doTest(212        "interface Foo : InterfaceWithToJSON { };" "interface Test { Foo toJSON(); };",213        False,214        "inherited interface with toJSON should be a JSON type",215    )216    for type in nonJsonTypes:217        doTest(218            "interface Test { %s toJSON(); };" % type,219            True,220            "%s should not be a JSON type" % type,221        )222        doTest(223            "interface Test { sequence<%s> toJSON(); };" % type,224            True,225            "sequence<%s> should not be a JSON type" % type,226        )227        doTest(228            "dictionary Foo { %s foo; }; " "interface Test { Foo toJSON(); }; " % type,229            True,230            "Dictionary containing a non-JSON type (%s) should not be a JSON type"231            % type,232        )233        doTest(234            "dictionary Foo { %s foo; }; dictionary Bar : Foo { }; "235            "interface Test { Bar toJSON(); }; " % type,236            True,237            "dictionary whose ancestors only contain non-JSON types should not be a JSON type",238        )239        doTest(240            "interface Test { record<DOMString, %s> toJSON(); };" % type,241            True,242            "record<DOMString, %s> should not be a JSON type" % type,243        )244        doTest(245            "interface Test { record<ByteString, %s> toJSON(); };" % type,246            True,247            "record<ByteString, %s> should not be a JSON type" % type,248        )249        doTest(250            "interface Test { record<USVString, %s> toJSON(); };" % type,251            True,252            "record<USVString, %s> should not be a JSON type" % type,253        )254        if type != "any":255            doTest(256                "interface Foo { object toJSON(); }; "257                "interface Test { (Foo or %s) toJSON(); };" % type,258                True,259                "union containing a non-JSON type (%s) should not be a JSON type"260                % type,261            )262            doTest(263                "interface test { %s? toJSON(); };" % type,264                True,265                "Nullable type (%s) should not be a JSON type" % type,266            )267    doTest(268        "dictionary Foo { long foo; any bar; };" "interface Test { Foo toJSON(); };",269        True,270        "dictionary containing a non-JSON type should not be a JSON type",271    )272    doTest(273        "interface Foo : InterfaceWithoutToJSON { }; "274        "interface Test { Foo toJSON(); };",275        True,276        "interface without toJSON should not be a JSON type",...calendar-date-add.js
Source:calendar-date-add.js  
1// Copyright 2021 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --harmony-temporal5// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateadd6let cal = new Temporal.Calendar("iso8601");7let p1y = new Temporal.Duration(1);8let p4y = new Temporal.Duration(4);9let p5m = new Temporal.Duration(0, 5);10let p1y2m = new Temporal.Duration(1,2);11let p1y4d = new Temporal.Duration(1,0,0,4);12let p1y2m4d = new Temporal.Duration(1,2,0,4);13let p10d = new Temporal.Duration(0,0,0,10);14let p1w = new Temporal.Duration(0,0,1);15let p6w = new Temporal.Duration(0,0,6);16let p2w3d = new Temporal.Duration(0,0,2,3);17let p1y2w = new Temporal.Duration(1,0,2);18let p2m3w = new Temporal.Duration(0,2,3);19assertEquals("2021-02-28", cal.dateAdd("2020-02-29", p1y).toJSON());20assertEquals("2024-02-29", cal.dateAdd("2020-02-29", p4y).toJSON());21assertEquals("2022-07-16", cal.dateAdd("2021-07-16", p1y).toJSON());22assertEquals("2021-12-16", cal.dateAdd("2021-07-16", p5m).toJSON());23assertEquals("2022-01-16", cal.dateAdd("2021-08-16", p5m).toJSON());24assertEquals("2022-03-31", cal.dateAdd("2021-10-31", p5m).toJSON());25assertEquals("2022-02-28", cal.dateAdd("2021-09-30", p5m).toJSON());26assertEquals("2020-02-29", cal.dateAdd("2019-09-30", p5m).toJSON());27assertEquals("2020-03-01", cal.dateAdd("2019-10-01", p5m).toJSON());28assertEquals("2022-09-16", cal.dateAdd("2021-07-16", p1y2m).toJSON());29assertEquals("2023-01-30", cal.dateAdd("2021-11-30", p1y2m).toJSON());30assertEquals("2023-02-28", cal.dateAdd("2021-12-31", p1y2m).toJSON());31assertEquals("2024-02-29", cal.dateAdd("2022-12-31", p1y2m).toJSON());32assertEquals("2022-07-20", cal.dateAdd("2021-07-16", p1y4d).toJSON());33assertEquals("2022-03-03", cal.dateAdd("2021-02-27", p1y4d).toJSON());34assertEquals("2024-03-02", cal.dateAdd("2023-02-27", p1y4d).toJSON());35assertEquals("2023-01-03", cal.dateAdd("2021-12-30", p1y4d).toJSON());36assertEquals("2022-08-03", cal.dateAdd("2021-07-30", p1y4d).toJSON());37assertEquals("2022-07-04", cal.dateAdd("2021-06-30", p1y4d).toJSON());38assertEquals("2022-09-20", cal.dateAdd("2021-07-16", p1y2m4d).toJSON());39assertEquals("2022-05-01", cal.dateAdd("2021-02-27", p1y2m4d).toJSON());40assertEquals("2022-04-30", cal.dateAdd("2021-02-26", p1y2m4d).toJSON());41assertEquals("2024-04-30", cal.dateAdd("2023-02-26", p1y2m4d).toJSON());42assertEquals("2023-03-04", cal.dateAdd("2021-12-30", p1y2m4d).toJSON());43assertEquals("2022-10-04", cal.dateAdd("2021-07-30", p1y2m4d).toJSON());44assertEquals("2022-09-03", cal.dateAdd("2021-06-30", p1y2m4d).toJSON());45assertEquals("2021-07-26", cal.dateAdd("2021-07-16", p10d).toJSON());46assertEquals("2021-08-05", cal.dateAdd("2021-07-26", p10d).toJSON());47assertEquals("2022-01-05", cal.dateAdd("2021-12-26", p10d).toJSON());48assertEquals("2020-03-07", cal.dateAdd("2020-02-26", p10d).toJSON());49assertEquals("2021-03-08", cal.dateAdd("2021-02-26", p10d).toJSON());50assertEquals("2020-02-29", cal.dateAdd("2020-02-19", p10d).toJSON());51assertEquals("2021-03-01", cal.dateAdd("2021-02-19", p10d).toJSON());52assertEquals("2021-02-26", cal.dateAdd("2021-02-19", p1w).toJSON());53assertEquals("2021-03-06", cal.dateAdd("2021-02-27", p1w).toJSON());54assertEquals("2020-03-05", cal.dateAdd("2020-02-27", p1w).toJSON());55assertEquals("2021-12-31", cal.dateAdd("2021-12-24", p1w).toJSON());56assertEquals("2022-01-03", cal.dateAdd("2021-12-27", p1w).toJSON());57assertEquals("2021-02-03", cal.dateAdd("2021-01-27", p1w).toJSON());58assertEquals("2021-07-04", cal.dateAdd("2021-06-27", p1w).toJSON());59assertEquals("2021-08-03", cal.dateAdd("2021-07-27", p1w).toJSON());60assertEquals("2021-04-02", cal.dateAdd("2021-02-19", p6w).toJSON());61assertEquals("2021-04-10", cal.dateAdd("2021-02-27", p6w).toJSON());62assertEquals("2020-04-09", cal.dateAdd("2020-02-27", p6w).toJSON());63assertEquals("2022-02-04", cal.dateAdd("2021-12-24", p6w).toJSON());64assertEquals("2022-02-07", cal.dateAdd("2021-12-27", p6w).toJSON());65assertEquals("2021-03-10", cal.dateAdd("2021-01-27", p6w).toJSON());66assertEquals("2021-08-08", cal.dateAdd("2021-06-27", p6w).toJSON());67assertEquals("2021-09-07", cal.dateAdd("2021-07-27", p6w).toJSON());68assertEquals("2020-03-17", cal.dateAdd("2020-02-29", p2w3d).toJSON());69assertEquals("2020-03-16", cal.dateAdd("2020-02-28", p2w3d).toJSON());70assertEquals("2021-03-17", cal.dateAdd("2021-02-28", p2w3d).toJSON());71assertEquals("2021-01-14", cal.dateAdd("2020-12-28", p2w3d).toJSON());72assertEquals("2021-03-14", cal.dateAdd("2020-02-29", p1y2w).toJSON());73assertEquals("2021-03-14", cal.dateAdd("2020-02-28", p1y2w).toJSON());74assertEquals("2022-03-14", cal.dateAdd("2021-02-28", p1y2w).toJSON());75assertEquals("2022-01-11", cal.dateAdd("2020-12-28", p1y2w).toJSON());76assertEquals("2020-05-20", cal.dateAdd("2020-02-29", p2m3w).toJSON());77assertEquals("2020-05-19", cal.dateAdd("2020-02-28", p2m3w).toJSON());78assertEquals("2021-05-19", cal.dateAdd("2021-02-28", p2m3w).toJSON());79assertEquals("2021-03-21", cal.dateAdd("2020-12-28", p2m3w).toJSON());80assertEquals("2020-03-20", cal.dateAdd("2019-12-28", p2m3w).toJSON());81assertEquals("2020-01-18", cal.dateAdd("2019-10-28", p2m3w).toJSON());...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
