1 // ♓️🪡 सूत्र ∷ xsd/functions.test.js 
   2 // ==================================================================== 
   4 // Copyright © 2023 Lady [@ Lady’s Computer]. 
   6 // This Source Code Form is subject to the terms of the Mozilla Public 
   7 // License, v. 2.0. If a copy of the MPL was not distributed with this 
   8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>. 
  18 } from "../dev-deps.js"; 
  27   dayCanonicalFragmentMap
, 
  30   dayTimeDurationCanonicalMap
, 
  34   decimalPtCanonicalMap
, 
  45   gMonthDayCanonicalMap
, 
  50   gYearMonthCanonicalMap
, 
  54   hourCanonicalFragmentMap
, 
  56   minuteCanonicalFragmentMap
, 
  58   monthCanonicalFragmentMap
, 
  62   noDecimalPtCanonicalMap
, 
  63   scientificCanonicalMap
, 
  65   secondCanonicalFragmentMap
, 
  67   specialRepCanonicalMap
, 
  74   timezoneCanonicalFragmentMap
, 
  76   unsignedDecimalPtCanonicalMap
, 
  79   unsignedNoDecimalPtCanonicalMap
, 
  80   unsignedScientificCanonicalMap
, 
  81   yearCanonicalFragmentMap
, 
  83   yearMonthDurationCanonicalMap
, 
  85 } from "./functions.js"; 
  87 describe("unsignedNoDecimalMap", () => { 
  88   it("maps the value", () => { 
  89     assertStrictEquals(unsignedNoDecimalMap("231"), 231); 
  92   it("throws an error if the value has a decimal point", () => { 
  94       unsignedNoDecimalMap("231."); 
  97       unsignedNoDecimalMap(".231"); 
 100       unsignedNoDecimalMap("23.1"); 
 104   it("throws an error if the value has a sign", () => { 
 106       unsignedNoDecimalMap("+231"); 
 109       unsignedNoDecimalMap("-231"); 
 113   it("throws an error if the value is not a string", () => { 
 115       unsignedNoDecimalMap(231); 
 120 describe("noDecimalMap", () => { 
 121   it("maps the value", () => { 
 122     assertStrictEquals(noDecimalMap("231"), 231); 
 123     assertStrictEquals(noDecimalMap("-69"), -69); 
 124     assertStrictEquals(noDecimalMap("+72"), +72); 
 125     assertStrictEquals(noDecimalMap("0"), 0); 
 126     assertStrictEquals(noDecimalMap("-0"), 0); 
 129   it("throws an error if the value has a decimal point", () => { 
 131       noDecimalMap("231."); 
 134       noDecimalMap(".231"); 
 137       noDecimalMap("23.1"); 
 141   it("throws an error if the value is not a string", () => { 
 148 describe("unsignedDecimalPtMap", () => { 
 149   it("maps the value", () => { 
 150     assertStrictEquals(unsignedDecimalPtMap("231."), 231); 
 151     assertStrictEquals(unsignedDecimalPtMap(".231"), .231); 
 152     assertStrictEquals(unsignedDecimalPtMap("23.1"), 23.1); 
 155   it("throws an error if the value has no decimal point", () => { 
 157       unsignedDecimalPtMap("231"); 
 161   it("throws an error if the value has a sign", () => { 
 163       unsignedDecimalPtMap("+231."); 
 166       unsignedDecimalPtMap("-231."); 
 170   it("throws an error if the value is not a string", () => { 
 172       unsignedDecimalPtMap(231); 
 177 describe("decimalPtMap", () => { 
 178   it("maps the value", () => { 
 179     assertStrictEquals(decimalPtMap("231."), 231); 
 180     assertStrictEquals(decimalPtMap("+.231"), .231); 
 181     assertStrictEquals(decimalPtMap("-23.1"), -23.1); 
 182     assertStrictEquals(decimalPtMap("0.0"), 0); 
 183     assertStrictEquals(decimalPtMap("-0.0"), 0); 
 186   it("throws an error if the value has no decimal point", () => { 
 192   it("throws an error if the value is not a string", () => { 
 199 describe("scientificMap", () => { 
 200   it("maps the value", () => { 
 201     assertStrictEquals(scientificMap("23E1"), 230); 
 202     assertStrictEquals(scientificMap("+2.3E-1"), .23); 
 203     assertStrictEquals(scientificMap("-.23E1"), -2.3); 
 204     assertStrictEquals(scientificMap("0.0E0"), 0); 
 205     assertStrictEquals(scientificMap("-0.0E-0"), 0); 
 208   it("throws an error if the value has no E", () => { 
 210       scientificMap("231"); 
 214   it("throws an error if the value is not a string", () => { 
 221 describe("unsignedNoDecimalPtCanonicalMap", () => { 
 222   it("maps the value", () => { 
 223     assertStrictEquals(unsignedNoDecimalPtCanonicalMap(231), "231"); 
 225       unsignedNoDecimalPtCanonicalMap(1e23
), 
 226       "100000000000000000000000", 
 228     assertStrictEquals(unsignedNoDecimalPtCanonicalMap(0), "0"); 
 229     assertStrictEquals(unsignedNoDecimalPtCanonicalMap(-0), "0"); 
 232   it("throws an error if the value has a fractional part", () => { 
 234       unsignedNoDecimalPtCanonicalMap(23.1); 
 238   it("throws an error if the value is negative", () => { 
 240       unsignedNoDecimalPtCanonicalMap(-231); 
 244   it("throws an error if the value is not a number", () => { 
 246       unsignedNoDecimalPtCanonicalMap("231"); 
 251 describe("noDecimalPtCanonicalMap", () => { 
 252   it("maps the value", () => { 
 253     assertStrictEquals(noDecimalPtCanonicalMap(231), "231"); 
 254     assertStrictEquals(noDecimalPtCanonicalMap(-231), "-231"); 
 255     assertStrictEquals(noDecimalPtCanonicalMap(0), "0"); 
 256     assertStrictEquals(noDecimalPtCanonicalMap(-0), "0"); 
 259   it("throws an error if the value has a fractional part", () => { 
 261       noDecimalPtCanonicalMap(23.1); 
 265   it("throws an error if the value is not a number", () => { 
 267       noDecimalPtCanonicalMap("231"); 
 272 describe("unsignedDecimalPtCanonicalMap", () => { 
 273   it("maps the value", () => { 
 274     assertStrictEquals(unsignedDecimalPtCanonicalMap(4), "4.0"); 
 275     assertStrictEquals(unsignedDecimalPtCanonicalMap(231), "231.0"); 
 276     assertStrictEquals(unsignedDecimalPtCanonicalMap(23.1), "23.1"); 
 277     assertStrictEquals(unsignedDecimalPtCanonicalMap(.24), "0.24"); 
 279       unsignedDecimalPtCanonicalMap(10 ** 21.5), 
 280       "3162277660168379400000.0", 
 282     assertStrictEquals(unsignedDecimalPtCanonicalMap(.0085), "0.0085"); 
 284       unsignedDecimalPtCanonicalMap(10 ** -6.5), 
 285       "0.0000003162277660168379", 
 287     assertStrictEquals(unsignedDecimalPtCanonicalMap(0), "0.0"); 
 288     assertStrictEquals(unsignedDecimalPtCanonicalMap(-0), "0.0"); 
 291   it("throws an error if the value is negative", () => { 
 293       unsignedDecimalPtCanonicalMap(-231); 
 297   it("throws an error if the value is not a number", () => { 
 299       unsignedDecimalPtCanonicalMap("231.0"); 
 304 describe("decimalPtCanonicalMap", () => { 
 305   it("maps the value", () => { 
 306     assertStrictEquals(decimalPtCanonicalMap(231), "231.0"); 
 307     assertStrictEquals(decimalPtCanonicalMap(-23.1), "-23.1"); 
 308     assertStrictEquals(decimalPtCanonicalMap(0), "0.0"); 
 309     assertStrictEquals(decimalPtCanonicalMap(-0), "0.0"); 
 312   it("throws an error if the value is not a number", () => { 
 314       decimalPtCanonicalMap("231.0"); 
 319 describe("unsignedScientificCanonicalMap", () => { 
 320   it("maps the value", () => { 
 321     assertStrictEquals(unsignedScientificCanonicalMap(4), "4.0E0"); 
 322     assertStrictEquals(unsignedScientificCanonicalMap(231), "2.31E2"); 
 323     assertStrictEquals(unsignedScientificCanonicalMap(23), "2.3E1"); 
 324     assertStrictEquals(unsignedScientificCanonicalMap(.24), "2.4E-1"); 
 326       unsignedScientificCanonicalMap(10 ** 21.5), 
 327       "3.1622776601683794E21", 
 330       unsignedScientificCanonicalMap(.0085), 
 334       unsignedScientificCanonicalMap(10 ** -6.5), 
 335       "3.162277660168379E-7", 
 337     assertStrictEquals(unsignedScientificCanonicalMap(0), "0.0E0"); 
 338     assertStrictEquals(unsignedScientificCanonicalMap(-0), "0.0E0"); 
 341   it("throws an error if the value is negative", () => { 
 343       unsignedScientificCanonicalMap(-231); 
 347   it("throws an error if the value is not a number", () => { 
 349       unsignedScientificCanonicalMap("2.31E2"); 
 354 describe("scientificCanonicalMap", () => { 
 355   it("maps the value", () => { 
 356     assertStrictEquals(scientificCanonicalMap(231), "2.31E2"); 
 357     assertStrictEquals(scientificCanonicalMap(-.231), "-2.31E-1"); 
 358     assertStrictEquals(scientificCanonicalMap(0), "0.0E0"); 
 359     assertStrictEquals(scientificCanonicalMap(-0), "0.0E0"); 
 362   it("throws an error if the value is not a number", () => { 
 364       scientificCanonicalMap("2.31E2"); 
 369 describe("specialRepValue", () => { 
 370   it("maps the value", () => { 
 371     assertStrictEquals(specialRepValue("INF"), Infinity
); 
 372     assertStrictEquals(specialRepValue("+INF"), Infinity
); 
 373     assertStrictEquals(specialRepValue("-INF"), -Infinity
); 
 374     assertStrictEquals(specialRepValue("NaN"), NaN
); 
 377   it("throws an error if the value is not a special represention", () => { 
 379       specialRepValue("231"); 
 383   it("throws an error if the value is not a string", () => { 
 385       specialRepValue(Infinity
); 
 390 describe("specialRepCanonicalMap", () => { 
 391   it("maps the value", () => { 
 392     assertStrictEquals(specialRepCanonicalMap(Infinity
), "INF"); 
 393     assertStrictEquals(specialRepCanonicalMap(-Infinity
), "-INF"); 
 394     assertStrictEquals(specialRepCanonicalMap(NaN
), "NaN"); 
 397   it("throws an error if the value is not a special value", () => { 
 399       specialRepCanonicalMap(231); 
 403   it("throws an error if the value is not a number", () => { 
 405       specialRepCanonicalMap("NaN"); 
 410 describe("decimalLexicalMap", () => { 
 411   it("maps the value", () => { 
 412     assertStrictEquals(decimalLexicalMap("4.0"), 4); 
 413     assertStrictEquals(decimalLexicalMap("-231"), -231); 
 414     assertStrictEquals(decimalLexicalMap("+23.1"), 23.1); 
 415     assertStrictEquals(decimalLexicalMap("-0.24"), -0.24); 
 416     assertStrictEquals(decimalLexicalMap(".008500"), 0.0085); 
 417     assertStrictEquals(decimalLexicalMap("0"), 0); 
 418     assertStrictEquals(decimalLexicalMap("-0"), 0); 
 421   it("throws an error if the value is in exponential notation", () => { 
 423       decimalLexicalMap("23E1"); 
 427   it("throws an error if the value is not a string", () => { 
 429       decimalLexicalMap(231); 
 434 describe("decimalCanonicalMap", () => { 
 435   it("maps the value", () => { 
 436     assertStrictEquals(decimalCanonicalMap(4), "4"); 
 437     assertStrictEquals(decimalCanonicalMap(-231), "-231"); 
 438     assertStrictEquals(decimalCanonicalMap(23.1), "23.1"); 
 439     assertStrictEquals(decimalCanonicalMap(-.24), "-0.24"); 
 441       decimalCanonicalMap(10 ** 21.5), 
 442       "3162277660168379400000", 
 444     assertStrictEquals(decimalCanonicalMap(.0085), "0.0085"); 
 446       decimalCanonicalMap(10 ** -6.5), 
 447       "0.0000003162277660168379", 
 449     assertStrictEquals(decimalCanonicalMap(0), "0"); 
 450     assertStrictEquals(decimalCanonicalMap(-0), "0"); 
 453   it("throws an error if the value is not a number", () => { 
 455       decimalCanonicalMap("231"); 
 460 describe("floatLexicalMap", () => { 
 461   it("maps the value", () => { 
 462     assertStrictEquals(floatLexicalMap("4.0"), Math
.fround(4)); 
 463     assertStrictEquals(floatLexicalMap("-231"), Math
.fround(-231)); 
 464     assertStrictEquals(floatLexicalMap("+23.1"), Math
.fround(23.1)); 
 465     assertStrictEquals(floatLexicalMap("-0.24"), Math
.fround(-0.24)); 
 467       floatLexicalMap(".008500"), 
 470     assertStrictEquals(floatLexicalMap("23E1"), Math
.fround(230)); 
 471     assertStrictEquals(floatLexicalMap("4E-20"), Math
.fround(4e-20)); 
 472     assertStrictEquals(doubleLexicalMap("+0"), 0); 
 473     assertStrictEquals(doubleLexicalMap("-0"), -0); 
 474     assertStrictEquals(doubleLexicalMap("INF"), Infinity
); 
 475     assertStrictEquals(doubleLexicalMap("+INF"), Infinity
); 
 476     assertStrictEquals(doubleLexicalMap("-INF"), -Infinity
); 
 477     assertStrictEquals(doubleLexicalMap("NaN"), NaN
); 
 480   it("throws an error if the value is not a string", () => { 
 482       floatLexicalMap(231); 
 487 describe("doubleLexicalMap", () => { 
 488   it("maps the value", () => { 
 489     assertStrictEquals(doubleLexicalMap("4.0"), 4); 
 490     assertStrictEquals(doubleLexicalMap("-231"), -231); 
 491     assertStrictEquals(doubleLexicalMap("+23.1"), 23.1); 
 492     assertStrictEquals(doubleLexicalMap("-0.24"), -0.24); 
 493     assertStrictEquals(doubleLexicalMap(".008500"), 0.0085); 
 494     assertStrictEquals(doubleLexicalMap("23E1"), 230); 
 495     assertStrictEquals(doubleLexicalMap("4E-20"), 4e-20); 
 496     assertStrictEquals(doubleLexicalMap("+0"), 0); 
 497     assertStrictEquals(doubleLexicalMap("-0"), -0); 
 498     assertStrictEquals(doubleLexicalMap("INF"), Infinity
); 
 499     assertStrictEquals(doubleLexicalMap("+INF"), Infinity
); 
 500     assertStrictEquals(doubleLexicalMap("-INF"), -Infinity
); 
 501     assertStrictEquals(doubleLexicalMap("NaN"), NaN
); 
 504   it("throws an error if the value is not a string", () => { 
 506       doubleLexicalMap(231); 
 511 describe("floatCanonicalMap", () => { 
 512   it("maps the value", () => { 
 513     assertStrictEquals(floatCanonicalMap(4), "4.0E0"); 
 514     assertStrictEquals(floatCanonicalMap(-231), "-2.31E2"); 
 516       floatCanonicalMap(23.100000381469727), 
 517       "2.3100000381469727E1", 
 520       floatCanonicalMap(-0.23999999463558197), 
 521       "-2.3999999463558197E-1", 
 524       floatCanonicalMap(0.008500000461935997), 
 525       "8.500000461935997E-3", 
 528       floatCanonicalMap(3.1622776321769755e21
), 
 529       "3.1622776321769755E21", 
 532       floatCanonicalMap(3.1622775509276835e-7), 
 533       "3.1622775509276835E-7", 
 535     assertStrictEquals(floatCanonicalMap(0), "0.0E0"); 
 536     assertStrictEquals(floatCanonicalMap(-0), "-0.0E0"); 
 537     assertStrictEquals(floatCanonicalMap(Infinity
), "INF"); 
 538     assertStrictEquals(floatCanonicalMap(-Infinity
), "-INF"); 
 539     assertStrictEquals(floatCanonicalMap(NaN
), "NaN"); 
 542   it("throws an error if the value is not a float", () => { 
 544       floatCanonicalMap(23.1); 
 548   it("throws an error if the value is not a number", () => { 
 550       floatCanonicalMap("231"); 
 555 describe("doubleCanonicalMap", () => { 
 556   it("maps the value", () => { 
 557     assertStrictEquals(doubleCanonicalMap(4), "4.0E0"); 
 558     assertStrictEquals(doubleCanonicalMap(-231), "-2.31E2"); 
 559     assertStrictEquals(doubleCanonicalMap(23.1), "2.31E1"); 
 560     assertStrictEquals(doubleCanonicalMap(-0.24), "-2.4E-1"); 
 561     assertStrictEquals(doubleCanonicalMap(.0085), "8.5E-3"); 
 563       doubleCanonicalMap(10 ** 21.5), 
 564       "3.1622776601683794E21", 
 567       doubleCanonicalMap(10 ** -6.5), 
 568       "3.162277660168379E-7", 
 570     assertStrictEquals(doubleCanonicalMap(0), "0.0E0"); 
 571     assertStrictEquals(doubleCanonicalMap(-0), "-0.0E0"); 
 572     assertStrictEquals(doubleCanonicalMap(Infinity
), "INF"); 
 573     assertStrictEquals(doubleCanonicalMap(-Infinity
), "-INF"); 
 574     assertStrictEquals(doubleCanonicalMap(NaN
), "NaN"); 
 577   it("throws an error if the value is not a number", () => { 
 579       doubleCanonicalMap("231"); 
 584 describe("durationMap", () => { 
 585   it("maps the value", () => { 
 586     assertEquals(durationMap("P0Y0M0DT0H0M0.0S"), { 
 590     assertStrictEquals(durationMap("-P0Y0M0DT0H0M0.0S").months
, 0); 
 591     assertStrictEquals(durationMap("-P0Y0M0DT0H0M0.0S").seconds
, 0); 
 592     assertEquals(durationMap("-P1Y2M"), { months: -14, seconds: 0 }); 
 593     assertStrictEquals(durationMap("-P1Y2M").seconds
, 0); 
 594     assertEquals(durationMap("-P3DT5H7M11S"), { 
 598     assertStrictEquals(durationMap("-P3DT5H7M11S").months
, 0); 
 599     assertEquals(durationMap("-P1Y2M3DT5H7M11.13S"), { 
 605   it("throws an error if the value is not a string", () => { 
 610       durationMap({ months: 0, seconds: 0 }); 
 614   it("throws an error if the value has no fields", () => { 
 620   it("throws an error if the value has a T but no time", () => { 
 622       durationMap("P0Y0M0DT"); 
 627 describe("yearMonthDurationMap", () => { 
 628   it("maps the value", () => { 
 629     assertEquals(yearMonthDurationMap("P0Y0M"), { 
 633     assertStrictEquals(yearMonthDurationMap("-P0Y0M").months
, 0); 
 634     assertStrictEquals(yearMonthDurationMap("-P0Y0M").seconds
, 0); 
 635     assertEquals(yearMonthDurationMap("-P1Y2M"), { 
 639     assertStrictEquals(yearMonthDurationMap("-P1Y2M").seconds
, 0); 
 642   it("throws an error if the value is not a string", () => { 
 644       yearMonthDurationMap(0); 
 647       yearMonthDurationMap({ months: 0, seconds: 0 }); 
 651   it("throws an error if the value has no fields", () => { 
 653       yearMonthDurationMap("P"); 
 658 describe("dayTimeDurationMap", () => { 
 659   it("maps the value", () => { 
 660     assertEquals(dayTimeDurationMap("P0DT0H0M0.0S"), { 
 664     assertStrictEquals(dayTimeDurationMap("-P0DT0H0M0.0S").months
, 0); 
 665     assertStrictEquals(dayTimeDurationMap("-P0DT0H0M0.0S").seconds
, 0); 
 666     assertEquals(dayTimeDurationMap("-P3DT5H7M11.13S"), { 
 671       dayTimeDurationMap("-P3DT5H7M11.13S").months
, 
 676   it("throws an error if the value is not a string", () => { 
 678       dayTimeDurationMap(0); 
 681       dayTimeDurationMap({ months: 0, seconds: 0 }); 
 685   it("throws an error if the value has no fields", () => { 
 687       dayTimeDurationMap("P"); 
 691   it("throws an error if the value has a T but no time", () => { 
 693       dayTimeDurationMap("P0DT"); 
 698 describe("durationCanonicalMap", () => { 
 699   it("maps the value", () => { 
 701       durationCanonicalMap({ months: 0, seconds: 0 }), 
 705       durationCanonicalMap({ months: -0, seconds: -0 }), 
 709       durationCanonicalMap({ months: 23, seconds: 1234.5 }), 
 713       durationCanonicalMap({ months: -14, seconds: -277631 }), 
 718   it("throws an error if the value is not a duration", () => { 
 720       durationCanonicalMap("PT0S"); 
 723       durationCanonicalMap({}); 
 726       durationCanonicalMap(0); 
 730   it("throws an error if the signs of the terms do not match", () => { 
 732       durationCanonicalMap({ months: 1, seconds: -1 }); 
 737 describe("yearMonthDurationCanonicalMap", () => { 
 738   it("maps the value", () => { 
 740       yearMonthDurationCanonicalMap({ months: 0, seconds: 0 }), 
 744       yearMonthDurationCanonicalMap({ months: -0, seconds: -0 }), 
 748       yearMonthDurationCanonicalMap({ months: 23, seconds: 0 }), 
 752       yearMonthDurationCanonicalMap({ months: -14, seconds: 0 }), 
 757   it("throws an error if the value is not a duration", () => { 
 759       yearMonthDurationCanonicalMap("P0M"); 
 762       yearMonthDurationCanonicalMap({}); 
 765       yearMonthDurationCanonicalMap(0); 
 769   it("throws an error if the value of seconds is not zero", () => { 
 771       yearMonthDurationCanonicalMap({ months: 1, seconds: 1 }); 
 776 describe("dayTimeDurationCanonicalMap", () => { 
 777   it("maps the value", () => { 
 779       dayTimeDurationCanonicalMap({ months: 0, seconds: 0 }), 
 783       dayTimeDurationCanonicalMap({ months: -0, seconds: -0 }), 
 787       dayTimeDurationCanonicalMap({ months: 0, seconds: 1234.5 }), 
 791       dayTimeDurationCanonicalMap({ months: 0, seconds: -277631 }), 
 796   it("throws an error if the value is not a duration", () => { 
 798       dayTimeDurationCanonicalMap("PT0S"); 
 801       dayTimeDurationCanonicalMap({}); 
 804       dayTimeDurationCanonicalMap(0); 
 808   it("throws an error if the value of months is not zero", () => { 
 810       dayTimeDurationCanonicalMap({ months: 1, seconds: 1 }); 
 815 describe("daysInMonth", () => { 
 816   it("returns the correct value when no year is supplied", () => { 
 817     assertStrictEquals(daysInMonth(undefined, 1), 31); 
 818     assertStrictEquals(daysInMonth(undefined, 2), 28); 
 819     assertStrictEquals(daysInMonth(undefined, 3), 31); 
 820     assertStrictEquals(daysInMonth(undefined, 4), 30); 
 821     assertStrictEquals(daysInMonth(undefined, 5), 31); 
 822     assertStrictEquals(daysInMonth(undefined, 6), 30); 
 823     assertStrictEquals(daysInMonth(undefined, 7), 31); 
 824     assertStrictEquals(daysInMonth(undefined, 8), 31); 
 825     assertStrictEquals(daysInMonth(undefined, 9), 30); 
 826     assertStrictEquals(daysInMonth(undefined, 10), 31); 
 827     assertStrictEquals(daysInMonth(undefined, 11), 30); 
 828     assertStrictEquals(daysInMonth(undefined, 12), 31); 
 831   it("returns the correct value when a year is supplied", () => { 
 832     assertStrictEquals(daysInMonth(1972, 12), 31); 
 833     assertStrictEquals(daysInMonth(1972, 2), 29); 
 834     assertStrictEquals(daysInMonth(1970, 2), 28); 
 835     assertStrictEquals(daysInMonth(2000, 2), 29); 
 836     assertStrictEquals(daysInMonth(1000, 2), 28); 
 837     assertStrictEquals(daysInMonth(800, 2), 29); 
 838     assertStrictEquals(daysInMonth(100, 2), 28); 
 839     assertStrictEquals(daysInMonth(0, 2), 29); 
 842   it("throws an error if the month is not an integer between 1 and 12", () => { 
 844       daysInMonth(undefined, 0); 
 847       daysInMonth(undefined, 13); 
 850       daysInMonth(undefined, "1"); 
 854   it("throws an error if the year is not undefined or an integer", () => { 
 856       daysInMonth(null, 1); 
 859       daysInMonth(2.31, 1); 
 862       daysInMonth("undefined", 1); 
 870 describe("newDateTime", () => { 
 871   it("returns a new datetime object", () => { 
 872     assertEquals(newDateTime(1, 1, 1, 0, 0, 0, 0), { 
 881     assertEquals(newDateTime(-1, 12, 31, 23, 59, 59.99, -840), { 
 888       timezoneOffset: -840, 
 892   it("fills absent values with undefined", () => { 
 893     assertEquals(newDateTime(), { 
 900       timezoneOffset: undefined, 
 904   it("normalizes the date", () => { 
 905     assertEquals(newDateTime(1, 2, 31, 24), { 
 912       timezoneOffset: undefined, 
 914     assertEquals(newDateTime(1, undefined, 31, 24), { 
 921       timezoneOffset: undefined, 
 925   it("forbids out‐of‐range values", () => { 
 927       newDateTime(undefined, 0); 
 930       newDateTime(undefined, 13); 
 933       newDateTime(undefined, undefined, 0); 
 936       newDateTime(undefined, undefined, 32); 
 939       newDateTime(undefined, undefined, undefined, -1); 
 942       newDateTime(undefined, undefined, undefined, 25); 
 945       newDateTime(undefined, undefined, undefined, undefined, -1); 
 948       newDateTime(undefined, undefined, undefined, undefined, 61); 
 994   it("forbids values of the incorrect type", () => { 
1001     assertThrows(() => { 
1002       newDateTime(undefined, 1.23); 
1004     assertThrows(() => { 
1005       newDateTime(undefined, "1"); 
1007     assertThrows(() => { 
1008       newDateTime(undefined, undefined, 1.23); 
1010     assertThrows(() => { 
1011       newDateTime(undefined, undefined, "1"); 
1013     assertThrows(() => { 
1014       newDateTime(undefined, undefined, undefined, 1.23); 
1016     assertThrows(() => { 
1017       newDateTime(undefined, undefined, undefined, "1"); 
1019     assertThrows(() => { 
1020       newDateTime(undefined, undefined, undefined, undefined, 1.23); 
1022     assertThrows(() => { 
1023       newDateTime(undefined, undefined, undefined, undefined, "1"); 
1025     assertThrows(() => { 
1035     assertThrows(() => { 
1046     assertThrows(() => { 
1060 describe("dateTimePlusDuration", () => { 
1061   it("fills absent values with undefined", () => { 
1062     assertEquals(dateTimePlusDuration({ months: 0, seconds: 0 }, {}), { 
1069       timezoneOffset: undefined, 
1073   it("correctly adds the duration to the datetime", () => { 
1074     // These examples are taken from the X·S·D spec. 
1075     const fuzzyResult 
= dateTimePlusDuration({ 
1087     assertObjectMatch(fuzzyResult
, { 
1093       // seconds must be matched fuzzily 
1096     assertAlmostEquals(fuzzyResult
.second
, 17.3); 
1098       dateTimePlusDuration({ months: -3, seconds: 0 }, { 
1109         timezoneOffset: undefined, 
1113       dateTimePlusDuration({ months: 0, seconds: 118800 }, { 
1125         timezoneOffset: undefined, 
1129       dateTimePlusDuration( 
1130         { months: 1, seconds: 0 }, 
1131         dateTimePlusDuration({ months: 0, seconds: 86400 }, { 
1144         timezoneOffset: undefined, 
1148       dateTimePlusDuration( 
1149         { months: 0, seconds: 86400 }, 
1150         dateTimePlusDuration({ months: 1, seconds: 0 }, { 
1163         timezoneOffset: undefined, 
1168   it("follows 28 February with 01 March", () => { 
1170       dateTimePlusDuration({ months: 0, seconds: 86400 }, { 
1181         timezoneOffset: undefined, 
1186   it("allows 29 February without a year", () => { 
1188       dateTimePlusDuration({ months: 0, seconds: 1 }, { 
1199         timezoneOffset: undefined, 
1204   it("follows 29 February with 01 March", () => { 
1206       dateTimePlusDuration({ months: 0, seconds: 86400 }, { 
1217         timezoneOffset: undefined, 
1222   it("throws if not provided with a valid duration", () => { 
1223     assertThrows(() => { 
1224       dateTimePlusDuration({ months: 0 }, {}); 
1226     assertThrows(() => { 
1227       dateTimePlusDuration({ seconds: 0 }, {}); 
1229     assertThrows(() => { 
1230       dateTimePlusDuration({}, {}); 
1232     assertThrows(() => { 
1233       dateTimePlusDuration(0, {}); 
1235     assertThrows(() => { 
1236       dateTimePlusDuration("PT0S", {}); 
1240   it("throws if not provided with a valid date·time", () => { 
1241     assertThrows(() => { 
1242       dateTimePlusDuration({ months: 0, seconds: 0 }, 0); 
1244     assertThrows(() => { 
1245       dateTimePlusDuration({ seconds: 0 }, "2000-01-12T12:13:14Z"); 
1250 describe("timeOnTimeline", () => { 
1251   it("gets the time", () => { 
1272         timezoneOffset: 840, 
1276     assertStrictEquals(timeOnTimeline({}), 62230204800); 
1277     assertStrictEquals(timeOnTimeline({ year: 0 }), -86400); 
1280   it("throws if not provided with a valid date·time", () => { 
1281     assertThrows(() => { 
1284     assertThrows(() => { 
1285       timeOnTimeline("2000-01-12T12:13:14Z"); 
1290 describe("yearFragValue", () => { 
1291   it("maps the value", () => { 
1292     assertStrictEquals(yearFragValue("0001"), 1); 
1293     assertStrictEquals(yearFragValue("-0000"), 0); 
1294     assertStrictEquals(yearFragValue("-10000"), -10000); 
1295     assertStrictEquals(yearFragValue("99999"), 99999); 
1298   it("throws an error if the value is not a string", () => { 
1299     assertThrows(() => { 
1304   it("throws an error if the value is not a valid yearFrag", () => { 
1305     assertThrows(() => { 
1308     assertThrows(() => { 
1311     assertThrows(() => { 
1312       yearFragValue("01000"); 
1317 describe("monthFragValue", () => { 
1318   it("maps the value", () => { 
1319     assertStrictEquals(monthFragValue("01"), 1); 
1320     assertStrictEquals(monthFragValue("10"), 10); 
1321     assertStrictEquals(monthFragValue("12"), 12); 
1324   it("throws an error if the value is not a string", () => { 
1325     assertThrows(() => { 
1330   it("throws an error if the value is not a valid monthFrag", () => { 
1331     assertThrows(() => { 
1334     assertThrows(() => { 
1335       monthFragValue("1"); 
1337     assertThrows(() => { 
1338       monthFragValue("-1"); 
1340     assertThrows(() => { 
1341       monthFragValue("-01"); 
1343     assertThrows(() => { 
1344       monthFragValue("00"); 
1346     assertThrows(() => { 
1347       monthFragValue("13"); 
1349     assertThrows(() => { 
1350       monthFragValue("20"); 
1355 describe("dayFragValue", () => { 
1356   it("maps the value", () => { 
1357     assertStrictEquals(dayFragValue("01"), 1); 
1358     assertStrictEquals(dayFragValue("10"), 10); 
1359     assertStrictEquals(dayFragValue("19"), 19); 
1360     assertStrictEquals(dayFragValue("20"), 20); 
1361     assertStrictEquals(dayFragValue("29"), 29); 
1362     assertStrictEquals(dayFragValue("30"), 30); 
1363     assertStrictEquals(dayFragValue("31"), 31); 
1366   it("throws an error if the value is not a string", () => { 
1367     assertThrows(() => { 
1372   it("throws an error if the value is not a valid dayFrag", () => { 
1373     assertThrows(() => { 
1376     assertThrows(() => { 
1379     assertThrows(() => { 
1382     assertThrows(() => { 
1383       dayFragValue("-01"); 
1385     assertThrows(() => { 
1388     assertThrows(() => { 
1391     assertThrows(() => { 
1397 describe("hourFragValue", () => { 
1398   it("maps the value", () => { 
1399     assertStrictEquals(hourFragValue("00"), 0); 
1400     assertStrictEquals(hourFragValue("01"), 1); 
1401     assertStrictEquals(hourFragValue("10"), 10); 
1402     assertStrictEquals(hourFragValue("19"), 19); 
1403     assertStrictEquals(hourFragValue("20"), 20); 
1404     assertStrictEquals(hourFragValue("23"), 23); 
1407   it("throws an error if the value is not a string", () => { 
1408     assertThrows(() => { 
1413   it("throws an error if the value is not a valid hourFrag", () => { 
1414     assertThrows(() => { 
1417     assertThrows(() => { 
1420     assertThrows(() => { 
1421       hourFragValue("-1"); 
1423     assertThrows(() => { 
1424       hourFragValue("-01"); 
1426     assertThrows(() => { 
1427       hourFragValue("24"); 
1429     assertThrows(() => { 
1430       hourFragValue("30"); 
1432     assertThrows(() => { 
1433       hourFragValue("01.23"); 
1438 describe("minuteFragValue", () => { 
1439   it("maps the value", () => { 
1440     assertStrictEquals(minuteFragValue("00"), 0); 
1441     assertStrictEquals(minuteFragValue("01"), 1); 
1442     assertStrictEquals(minuteFragValue("10"), 10); 
1443     assertStrictEquals(minuteFragValue("19"), 19); 
1444     assertStrictEquals(minuteFragValue("50"), 50); 
1445     assertStrictEquals(minuteFragValue("59"), 59); 
1448   it("throws an error if the value is not a string", () => { 
1449     assertThrows(() => { 
1454   it("throws an error if the value is not a valid minuteFrag", () => { 
1455     assertThrows(() => { 
1456       minuteFragValue(""); 
1458     assertThrows(() => { 
1459       minuteFragValue("1"); 
1461     assertThrows(() => { 
1462       minuteFragValue("-1"); 
1464     assertThrows(() => { 
1465       minuteFragValue("-01"); 
1467     assertThrows(() => { 
1468       minuteFragValue("60"); 
1470     assertThrows(() => { 
1471       minuteFragValue("01.23"); 
1476 describe("secondFragValue", () => { 
1477   it("maps the value", () => { 
1478     assertStrictEquals(secondFragValue("00"), 0); 
1479     assertStrictEquals(secondFragValue("00.00000"), 0); 
1480     assertStrictEquals(secondFragValue("01"), 1); 
1481     assertStrictEquals(secondFragValue("10"), 10); 
1482     assertStrictEquals(secondFragValue("19"), 19); 
1483     assertStrictEquals(secondFragValue("50"), 50); 
1484     assertStrictEquals(secondFragValue("59"), 59); 
1485     assertStrictEquals(secondFragValue("59.99"), 59.99); 
1488   it("throws an error if the value is not a string", () => { 
1489     assertThrows(() => { 
1494   it("throws an error if the value is not a valid secondFrag", () => { 
1495     assertThrows(() => { 
1496       secondFragValue(""); 
1498     assertThrows(() => { 
1499       secondFragValue("1"); 
1501     assertThrows(() => { 
1502       secondFragValue("-1"); 
1504     assertThrows(() => { 
1505       secondFragValue("-01"); 
1507     assertThrows(() => { 
1508       secondFragValue("60"); 
1513 describe("timezoneFragValue", () => { 
1514   it("maps the value", () => { 
1515     assertStrictEquals(timezoneFragValue("Z"), 0); 
1516     assertStrictEquals(timezoneFragValue("+00:00"), 0); 
1517     assertStrictEquals(timezoneFragValue("-00:00"), 0); 
1518     assertStrictEquals(timezoneFragValue("+00:01"), 1); 
1519     assertStrictEquals(timezoneFragValue("+00:59"), 59); 
1520     assertStrictEquals(timezoneFragValue("+01:23"), 83); 
1521     assertStrictEquals(timezoneFragValue("-09:23"), -563); 
1522     assertStrictEquals(timezoneFragValue("-10:23"), -623); 
1523     assertStrictEquals(timezoneFragValue("+13:59"), 839); 
1524     assertStrictEquals(timezoneFragValue("+14:00"), 840); 
1525     assertStrictEquals(timezoneFragValue("-14:00"), -840); 
1528   it("throws an error if the value is not a string", () => { 
1529     assertThrows(() => { 
1530       timezoneFragValue(0); 
1534   it("throws an error if the value is not a valid timezoneFrag", () => { 
1535     assertThrows(() => { 
1536       timezoneFragValue(""); 
1538     assertThrows(() => { 
1539       timezoneFragValue("0"); 
1541     assertThrows(() => { 
1542       timezoneFragValue("+Z"); 
1544     assertThrows(() => { 
1545       timezoneFragValue("-Z"); 
1547     assertThrows(() => { 
1548       timezoneFragValue("Z+00:00"); 
1550     assertThrows(() => { 
1551       timezoneFragValue("00:00"); 
1553     assertThrows(() => { 
1554       timezoneFragValue("0000"); 
1556     assertThrows(() => { 
1557       timezoneFragValue("+0000"); 
1559     assertThrows(() => { 
1560       timezoneFragValue("840"); 
1562     assertThrows(() => { 
1563       timezoneFragValue("+840"); 
1565     assertThrows(() => { 
1566       timezoneFragValue("+-00:00"); 
1568     assertThrows(() => { 
1569       timezoneFragValue("-+00:00"); 
1571     assertThrows(() => { 
1572       timezoneFragValue("+14:01"); 
1574     assertThrows(() => { 
1575       timezoneFragValue("+15:00"); 
1580 describe("dateTimeLexicalMap", () => { 
1581   it("maps the value", () => { 
1582     assertEquals(dateTimeLexicalMap("0001-01-01T00:00:00.00Z"), { 
1591     assertEquals(dateTimeLexicalMap("-0001-12-31T24:00:00Z"), { 
1600     assertEquals(dateTimeLexicalMap("-0000-01-01T00:00:00-00:00"), { 
1609     assertEquals(dateTimeLexicalMap("0001-01-01T00:00:00.00"), { 
1616       timezoneOffset: undefined, 
1618     assertEquals(dateTimeLexicalMap("99999-12-31T23:59:59.99+14:00"), { 
1625       timezoneOffset: 840, 
1627     assertEquals(dateTimeLexicalMap("1972-02-29T00:00:00"), { 
1634       timezoneOffset: undefined, 
1638   it("throws an error if the value is not a string", () => { 
1639     assertThrows(() => { 
1640       dateTimeLexicalMap(0); 
1644   it("throws an error if the value is not a valid dateTime", () => { 
1645     assertThrows(() => { 
1646       dateTimeLexicalMap(""); 
1648     assertThrows(() => { 
1649       dateTimeLexicalMap("1"); 
1651     assertThrows(() => { 
1652       dateTimeLexicalMap("10-10-10T00:00:00"); 
1654     assertThrows(() => { 
1655       dateTimeLexicalMap("2345-67-89T01:23:45"); 
1657     assertThrows(() => { 
1658       dateTimeLexicalMap("01000-10-10T10:10:10"); 
1660     assertThrows(() => { 
1661       dateTimeLexicalMap("0001-01-01T00:00:00.00+0000"); 
1663     assertThrows(() => { 
1664       dateTimeLexicalMap("0001-01-01T00:00:00.00+14:01"); 
1666     assertThrows(() => { 
1667       dateTimeLexicalMap("1970-02-29T00:00:00.00"); 
1672 describe("timeLexicalMap", () => { 
1673   it("maps the value", () => { 
1674     assertEquals(timeLexicalMap("00:00:00.00Z"), { 
1683     assertEquals(timeLexicalMap("24:00:00Z"), { 
1692     assertEquals(timeLexicalMap("23:59:59.99+14:00"), { 
1699       timezoneOffset: 840, 
1703   it("throws an error if the value is not a string", () => { 
1704     assertThrows(() => { 
1709   it("throws an error if the value is not a valid time", () => { 
1710     assertThrows(() => { 
1713     assertThrows(() => { 
1714       timeLexicalMap("1"); 
1716     assertThrows(() => { 
1717       timeLexicalMap("00:00"); 
1719     assertThrows(() => { 
1720       timeLexicalMap("23:45:67"); 
1722     assertThrows(() => { 
1723       timeLexicalMap("-10:10:10"); 
1725     assertThrows(() => { 
1726       timeLexicalMap("00:00:00.00+0000"); 
1728     assertThrows(() => { 
1729       timeLexicalMap("00:00:00.00+14:01"); 
1731     assertThrows(() => { 
1732       timeLexicalMap("T00:00:00"); 
1737 describe("dateLexicalMap", () => { 
1738   it("maps the value", () => { 
1739     assertEquals(dateLexicalMap("0001-01-01Z"), { 
1748     assertEquals(dateLexicalMap("-0001-12-31Z"), { 
1757     assertEquals(dateLexicalMap("-0000-01-01-00:00"), { 
1766     assertEquals(dateLexicalMap("0001-01-01"), { 
1773       timezoneOffset: undefined, 
1775     assertEquals(dateLexicalMap("99999-12-31+14:00"), { 
1782       timezoneOffset: 840, 
1784     assertEquals(dateLexicalMap("1972-02-29"), { 
1791       timezoneOffset: undefined, 
1795   it("throws an error if the value is not a string", () => { 
1796     assertThrows(() => { 
1801   it("throws an error if the value is not a valid date", () => { 
1802     assertThrows(() => { 
1805     assertThrows(() => { 
1806       dateLexicalMap("1"); 
1808     assertThrows(() => { 
1809       dateLexicalMap("10-10-10"); 
1811     assertThrows(() => { 
1812       dateLexicalMap("2345-67-89"); 
1814     assertThrows(() => { 
1815       dateLexicalMap("01000-10-10"); 
1817     assertThrows(() => { 
1818       dateLexicalMap("0001-01-01+0000"); 
1820     assertThrows(() => { 
1821       dateLexicalMap("0001-01-01+14:01"); 
1823     assertThrows(() => { 
1824       dateLexicalMap("1970-02-29"); 
1826     assertThrows(() => { 
1827       dateLexicalMap("1972-02-29T00:00:00"); 
1832 describe("gYearMonthLexicalMap", () => { 
1833   it("maps the value", () => { 
1834     assertEquals(gYearMonthLexicalMap("0001-01Z"), { 
1843     assertEquals(gYearMonthLexicalMap("-0001-12Z"), { 
1852     assertEquals(gYearMonthLexicalMap("-0000-01-00:00"), { 
1861     assertEquals(gYearMonthLexicalMap("0001-01"), { 
1868       timezoneOffset: undefined, 
1870     assertEquals(gYearMonthLexicalMap("99999-12+14:00"), { 
1877       timezoneOffset: 840, 
1879     assertEquals(gYearMonthLexicalMap("1972-02"), { 
1886       timezoneOffset: undefined, 
1890   it("throws an error if the value is not a string", () => { 
1891     assertThrows(() => { 
1892       gYearMonthLexicalMap(0); 
1896   it("throws an error if the value is not a valid gYearMonth", () => { 
1897     assertThrows(() => { 
1898       gYearMonthLexicalMap(""); 
1900     assertThrows(() => { 
1901       gYearMonthLexicalMap("1"); 
1903     assertThrows(() => { 
1904       gYearMonthLexicalMap("10-10"); 
1906     assertThrows(() => { 
1907       gYearMonthLexicalMap("2345-67"); 
1909     assertThrows(() => { 
1910       gYearMonthLexicalMap("01000-10"); 
1912     assertThrows(() => { 
1913       gYearMonthLexicalMap("0001-01+0000"); 
1915     assertThrows(() => { 
1916       gYearMonthLexicalMap("0001-01+14:01"); 
1918     assertThrows(() => { 
1919       gYearMonthLexicalMap("1970-01-01"); 
1921     assertThrows(() => { 
1922       gYearMonthLexicalMap("1972-02T00:00:00"); 
1927 describe("gYearLexicalMap", () => { 
1928   it("maps the value", () => { 
1929     assertEquals(gYearLexicalMap("0001Z"), { 
1938     assertEquals(gYearLexicalMap("-0001Z"), { 
1947     assertEquals(gYearLexicalMap("-0000-00:00"), { 
1956     assertEquals(gYearLexicalMap("0001"), { 
1963       timezoneOffset: undefined, 
1965     assertEquals(gYearLexicalMap("99999+14:00"), { 
1972       timezoneOffset: 840, 
1974     assertEquals(gYearLexicalMap("1972"), { 
1981       timezoneOffset: undefined, 
1985   it("throws an error if the value is not a string", () => { 
1986     assertThrows(() => { 
1991   it("throws an error if the value is not a valid gYear", () => { 
1992     assertThrows(() => { 
1993       gYearLexicalMap(""); 
1995     assertThrows(() => { 
1996       gYearLexicalMap("1"); 
1998     assertThrows(() => { 
1999       gYearLexicalMap("10"); 
2001     assertThrows(() => { 
2002       gYearLexicalMap("01000"); 
2004     assertThrows(() => { 
2005       gYearLexicalMap("0001+0000"); 
2007     assertThrows(() => { 
2008       gYearLexicalMap("0001+14:01"); 
2010     assertThrows(() => { 
2011       gYearLexicalMap("1970-01"); 
2013     assertThrows(() => { 
2014       gYearLexicalMap("1972T00:00:00"); 
2019 describe("gMonthDayLexicalMap", () => { 
2020   it("maps the value", () => { 
2021     assertEquals(gMonthDayLexicalMap("--01-01Z"), { 
2030     assertEquals(gMonthDayLexicalMap("--12-31Z"), { 
2039     assertEquals(gMonthDayLexicalMap("--01-01-00:00"), { 
2048     assertEquals(gMonthDayLexicalMap("--01-01"), { 
2055       timezoneOffset: undefined, 
2057     assertEquals(gMonthDayLexicalMap("--12-31+14:00"), { 
2064       timezoneOffset: 840, 
2066     assertEquals(gMonthDayLexicalMap("--02-29"), { 
2073       timezoneOffset: undefined, 
2077   it("throws an error if the value is not a string", () => { 
2078     assertThrows(() => { 
2079       gMonthDayLexicalMap(0); 
2083   it("throws an error if the value is not a valid gMonthDay", () => { 
2084     assertThrows(() => { 
2085       gMonthDayLexicalMap(""); 
2087     assertThrows(() => { 
2088       gMonthDayLexicalMap("1"); 
2090     assertThrows(() => { 
2091       gMonthDayLexicalMap("--67-89"); 
2093     assertThrows(() => { 
2094       gMonthDayLexicalMap("---10-10"); 
2096     assertThrows(() => { 
2097       gMonthDayLexicalMap("--01-01+0000"); 
2099     assertThrows(() => { 
2100       gMonthDayLexicalMap("--01-01+14:01"); 
2102     assertThrows(() => { 
2103       gMonthDayLexicalMap("--02-30"); 
2105     assertThrows(() => { 
2106       gMonthDayLexicalMap("1970-01-01"); 
2108     assertThrows(() => { 
2109       gMonthDayLexicalMap("--02-29T00:00:00"); 
2114 describe("gDayLexicalMap", () => { 
2115   it("maps the value", () => { 
2116     assertEquals(gDayLexicalMap("---01Z"), { 
2125     assertEquals(gDayLexicalMap("---31Z"), { 
2134     assertEquals(gDayLexicalMap("---01-00:00"), { 
2143     assertEquals(gDayLexicalMap("---01"), { 
2150       timezoneOffset: undefined, 
2152     assertEquals(gDayLexicalMap("---31+14:00"), { 
2159       timezoneOffset: 840, 
2163   it("throws an error if the value is not a string", () => { 
2164     assertThrows(() => { 
2169   it("throws an error if the value is not a valid gDay", () => { 
2170     assertThrows(() => { 
2173     assertThrows(() => { 
2174       gDayLexicalMap("1"); 
2176     assertThrows(() => { 
2177       gDayLexicalMap("10"); 
2179     assertThrows(() => { 
2180       gDayLexicalMap("---89"); 
2182     assertThrows(() => { 
2183       gDayLexicalMap("----10"); 
2185     assertThrows(() => { 
2186       gDayLexicalMap("---01+0000"); 
2188     assertThrows(() => { 
2189       gDayLexicalMap("---01+14:01"); 
2191     assertThrows(() => { 
2192       gDayLexicalMap("--01-01"); 
2194     assertThrows(() => { 
2195       gDayLexicalMap("1970-01-01"); 
2197     assertThrows(() => { 
2198       gDayLexicalMap("---29T00:00:00"); 
2203 describe("gMonthLexicalMap", () => { 
2204   it("maps the value", () => { 
2205     assertEquals(gMonthLexicalMap("--01Z"), { 
2214     assertEquals(gMonthLexicalMap("--12Z"), { 
2223     assertEquals(gMonthLexicalMap("--01-00:00"), { 
2232     assertEquals(gMonthLexicalMap("--01"), { 
2239       timezoneOffset: undefined, 
2241     assertEquals(gMonthLexicalMap("--12+14:00"), { 
2248       timezoneOffset: 840, 
2252   it("throws an error if the value is not a string", () => { 
2253     assertThrows(() => { 
2254       gMonthLexicalMap(0); 
2258   it("throws an error if the value is not a valid gMonth", () => { 
2259     assertThrows(() => { 
2260       gMonthLexicalMap(""); 
2262     assertThrows(() => { 
2263       gMonthLexicalMap("1"); 
2265     assertThrows(() => { 
2266       gMonthLexicalMap("01"); 
2268     assertThrows(() => { 
2269       gMonthLexicalMap("--67"); 
2271     assertThrows(() => { 
2272       gMonthLexicalMap("---10"); 
2274     assertThrows(() => { 
2275       gMonthLexicalMap("--01+0000"); 
2277     assertThrows(() => { 
2278       gMonthLexicalMap("--01+14:01"); 
2280     assertThrows(() => { 
2281       gMonthLexicalMap("--13"); 
2283     assertThrows(() => { 
2284       gMonthLexicalMap("1970-01-01"); 
2286     assertThrows(() => { 
2287       gMonthLexicalMap("--02T00:00:00"); 
2292 describe("yearCanonicalFragmentMap", () => { 
2293   it("maps the value", () => { 
2294     assertStrictEquals(yearCanonicalFragmentMap(1), "0001"); 
2295     assertStrictEquals(yearCanonicalFragmentMap(0), "0000"); 
2296     assertStrictEquals(yearCanonicalFragmentMap(-0), "0000"); 
2297     assertStrictEquals(yearCanonicalFragmentMap(-1), "-0001"); 
2298     assertStrictEquals(yearCanonicalFragmentMap(10000), "10000"); 
2299     assertStrictEquals(yearCanonicalFragmentMap(-10000), "-10000"); 
2302   it("throws an error if the value is not an integer", () => { 
2303     assertThrows(() => { 
2304       yearCanonicalFragmentMap("0001"); 
2306     assertThrows(() => { 
2307       yearCanonicalFragmentMap(1.2); 
2312 describe("monthCanonicalFragmentMap", () => { 
2313   it("maps the value", () => { 
2314     assertStrictEquals(monthCanonicalFragmentMap(1), "01"); 
2315     assertStrictEquals(monthCanonicalFragmentMap(12), "12"); 
2318   it("throws an error if the value is not a positive integer less than 13", () => { 
2319     assertThrows(() => { 
2320       monthCanonicalFragmentMap("01"); 
2322     assertThrows(() => { 
2323       monthCanonicalFragmentMap(0); 
2325     assertThrows(() => { 
2326       monthCanonicalFragmentMap(-1); 
2328     assertThrows(() => { 
2329       monthCanonicalFragmentMap(1.2); 
2331     assertThrows(() => { 
2332       monthCanonicalFragmentMap(13); 
2337 describe("dayCanonicalFragmentMap", () => { 
2338   it("maps the value", () => { 
2339     assertStrictEquals(dayCanonicalFragmentMap(1), "01"); 
2340     assertStrictEquals(dayCanonicalFragmentMap(12), "12"); 
2341     assertStrictEquals(dayCanonicalFragmentMap(21), "21"); 
2342     assertStrictEquals(dayCanonicalFragmentMap(30), "30"); 
2343     assertStrictEquals(dayCanonicalFragmentMap(31), "31"); 
2346   it("throws an error if the value is not a positive integer less than 32", () => { 
2347     assertThrows(() => { 
2348       dayCanonicalFragmentMap("01"); 
2350     assertThrows(() => { 
2351       dayCanonicalFragmentMap(0); 
2353     assertThrows(() => { 
2354       dayCanonicalFragmentMap(-1); 
2356     assertThrows(() => { 
2357       dayCanonicalFragmentMap(1.2); 
2359     assertThrows(() => { 
2360       dayCanonicalFragmentMap(32); 
2365 describe("hourCanonicalFragmentMap", () => { 
2366   it("maps the value", () => { 
2367     assertStrictEquals(hourCanonicalFragmentMap(0), "00"); 
2368     assertStrictEquals(hourCanonicalFragmentMap(-0), "00"); 
2369     assertStrictEquals(hourCanonicalFragmentMap(1), "01"); 
2370     assertStrictEquals(hourCanonicalFragmentMap(12), "12"); 
2371     assertStrictEquals(hourCanonicalFragmentMap(21), "21"); 
2372     assertStrictEquals(hourCanonicalFragmentMap(23), "23"); 
2375   it("throws an error if the value is not a nonnegative integer less than 24", () => { 
2376     assertThrows(() => { 
2377       hourCanonicalFragmentMap("00"); 
2379     assertThrows(() => { 
2380       hourCanonicalFragmentMap(-1); 
2382     assertThrows(() => { 
2383       hourCanonicalFragmentMap(1.2); 
2385     assertThrows(() => { 
2386       hourCanonicalFragmentMap(24); 
2391 describe("minuteCanonicalFragmentMap", () => { 
2392   it("maps the value", () => { 
2393     assertStrictEquals(minuteCanonicalFragmentMap(0), "00"); 
2394     assertStrictEquals(minuteCanonicalFragmentMap(-0), "00"); 
2395     assertStrictEquals(minuteCanonicalFragmentMap(1), "01"); 
2396     assertStrictEquals(minuteCanonicalFragmentMap(12), "12"); 
2397     assertStrictEquals(minuteCanonicalFragmentMap(21), "21"); 
2398     assertStrictEquals(minuteCanonicalFragmentMap(32), "32"); 
2399     assertStrictEquals(minuteCanonicalFragmentMap(45), "45"); 
2400     assertStrictEquals(minuteCanonicalFragmentMap(59), "59"); 
2403   it("throws an error if the value is not a nonnegative integer less than 60", () => { 
2404     assertThrows(() => { 
2405       minuteCanonicalFragmentMap("00"); 
2407     assertThrows(() => { 
2408       minuteCanonicalFragmentMap(-1); 
2410     assertThrows(() => { 
2411       minuteCanonicalFragmentMap(1.2); 
2413     assertThrows(() => { 
2414       minuteCanonicalFragmentMap(60); 
2419 describe("secondCanonicalFragmentMap", () => { 
2420   it("maps the value", () => { 
2421     assertStrictEquals(secondCanonicalFragmentMap(0), "00"); 
2422     assertStrictEquals(secondCanonicalFragmentMap(-0), "00"); 
2423     assertStrictEquals(secondCanonicalFragmentMap(1), "01"); 
2424     assertStrictEquals(secondCanonicalFragmentMap(1.2), "01.2"); 
2425     assertStrictEquals(secondCanonicalFragmentMap(12), "12"); 
2426     assertStrictEquals(secondCanonicalFragmentMap(21), "21"); 
2427     assertStrictEquals(secondCanonicalFragmentMap(23.1), "23.1"); 
2428     assertStrictEquals(secondCanonicalFragmentMap(32), "32"); 
2429     assertStrictEquals(secondCanonicalFragmentMap(45), "45"); 
2430     assertStrictEquals(secondCanonicalFragmentMap(59), "59"); 
2433   it("throws an error if the value is not a nonnegative decimal number less than 60", () => { 
2434     assertThrows(() => { 
2435       secondCanonicalFragmentMap("00"); 
2437     assertThrows(() => { 
2438       secondCanonicalFragmentMap(-1); 
2440     assertThrows(() => { 
2441       secondCanonicalFragmentMap(60); 
2446 describe("timezoneCanonicalFragmentMap", () => { 
2447   it("maps the value", () => { 
2448     assertStrictEquals(timezoneCanonicalFragmentMap(0), "Z"); 
2449     assertStrictEquals(timezoneCanonicalFragmentMap(-0), "Z"); 
2450     assertStrictEquals(timezoneCanonicalFragmentMap(1), "+00:01"); 
2451     assertStrictEquals(timezoneCanonicalFragmentMap(-1), "-00:01"); 
2452     assertStrictEquals(timezoneCanonicalFragmentMap(839), "+13:59"); 
2453     assertStrictEquals(timezoneCanonicalFragmentMap(-839), "-13:59"); 
2454     assertStrictEquals(timezoneCanonicalFragmentMap(840), "+14:00"); 
2455     assertStrictEquals(timezoneCanonicalFragmentMap(-840), "-14:00"); 
2458   it("throws an error if the value is not an integer between -840 and 840 inclusive", () => { 
2459     assertThrows(() => { 
2460       timezoneCanonicalFragmentMap("00"); 
2462     assertThrows(() => { 
2463       timezoneCanonicalFragmentMap(-841); 
2465     assertThrows(() => { 
2466       timezoneCanonicalFragmentMap(841); 
2468     assertThrows(() => { 
2469       timezoneCanonicalFragmentMap(1.2); 
2474 describe("dateTimeCanonicalMap", () => { 
2475   it("maps the value", () => { 
2477       dateTimeCanonicalMap({ 
2486       "0001-01-01T00:00:00Z", 
2489       dateTimeCanonicalMap({ 
2498       "0000-01-01T00:00:00Z", 
2501       dateTimeCanonicalMap({ 
2510       "0000-01-01T00:00:00Z", 
2513       dateTimeCanonicalMap({ 
2520         timezoneOffset: undefined, 
2522       "0001-01-01T00:00:00", 
2525       dateTimeCanonicalMap({ 
2532         timezoneOffset: 840, 
2534       "99999-12-31T23:59:59.99+14:00", 
2537       dateTimeCanonicalMap({ 
2544         timezoneOffset: undefined, 
2546       "1972-02-29T00:00:00", 
2550   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
2551     assertThrows(() => { 
2552       dateTimeCanonicalMap(0); 
2554     assertThrows(() => { 
2555       dateTimeCanonicalMap("0001-01-01T00:00:00Z"); 
2557     assertThrows(() => { 
2558       dateTimeCanonicalMap({ 
2569   it("throws an error if the value is not a complete dateTime value", () => { 
2570     assertThrows(() => { 
2571       dateTimeCanonicalMap({}); 
2573     assertThrows(() => { 
2574       dateTimeCanonicalMap({ 
2584 describe("timeCanonicalMap", () => { 
2585   it("maps the value", () => { 
2618         timezoneOffset: 840, 
2620       "23:59:59.99+14:00", 
2624   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
2625     assertThrows(() => { 
2626       timeCanonicalMap(0); 
2628     assertThrows(() => { 
2629       timeCanonicalMap("00:00:00Z"); 
2631     assertThrows(() => { 
2643   it("throws an error if the value is not a complete time value", () => { 
2644     assertThrows(() => { 
2645       timeCanonicalMap({}); 
2647     assertThrows(() => { 
2658     assertThrows(() => { 
2672 describe("dateCanonicalMap", () => { 
2673   it("maps the value", () => { 
2718         timezoneOffset: undefined, 
2730         timezoneOffset: 840, 
2732       "99999-12-31+14:00", 
2742         timezoneOffset: undefined, 
2748   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
2749     assertThrows(() => { 
2750       dateCanonicalMap(0); 
2752     assertThrows(() => { 
2753       dateCanonicalMap("0001-01-01Z"); 
2755     assertThrows(() => { 
2767   it("throws an error if the value is not a complete date value", () => { 
2768     assertThrows(() => { 
2769       dateCanonicalMap({}); 
2771     assertThrows(() => { 
2782     assertThrows(() => { 
2783       dateCanonicalMap({ year: 1972 }); 
2788 describe("gYearMonthCanonicalMap", () => { 
2789   it("maps the value", () => { 
2791       gYearMonthCanonicalMap({ 
2803       gYearMonthCanonicalMap({ 
2815       gYearMonthCanonicalMap({ 
2827       gYearMonthCanonicalMap({ 
2834         timezoneOffset: undefined, 
2839       gYearMonthCanonicalMap({ 
2846         timezoneOffset: 840, 
2851       gYearMonthCanonicalMap({ 
2858         timezoneOffset: undefined, 
2864   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
2865     assertThrows(() => { 
2866       gYearMonthCanonicalMap(0); 
2868     assertThrows(() => { 
2869       gYearMonthCanonicalMap("0001-01Z"); 
2871     assertThrows(() => { 
2872       gYearMonthCanonicalMap({ 
2883   it("throws an error if the value is not a complete yearMonth value", () => { 
2884     assertThrows(() => { 
2885       gYearMonthCanonicalMap({}); 
2887     assertThrows(() => { 
2888       gYearMonthCanonicalMap({ 
2898     assertThrows(() => { 
2899       gYearMonthCanonicalMap({ year: 1972, month: 12, day: 31 }); 
2901     assertThrows(() => { 
2902       gYearMonthCanonicalMap({ year: 1972 }); 
2907 describe("gYearCanonicalMap", () => { 
2908   it("maps the value", () => { 
2953         timezoneOffset: undefined, 
2965         timezoneOffset: 840, 
2977         timezoneOffset: undefined, 
2983   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
2984     assertThrows(() => { 
2985       gYearCanonicalMap(0); 
2987     assertThrows(() => { 
2988       gYearCanonicalMap("0001Z"); 
2990     assertThrows(() => { 
3002   it("throws an error if the value is not a complete gYear value", () => { 
3003     assertThrows(() => { 
3004       gYearCanonicalMap({}); 
3006     assertThrows(() => { 
3017     assertThrows(() => { 
3018       gYearCanonicalMap({ year: 1972, month: 12, day: 31 }); 
3023 describe("gMonthDayCanonicalMap", () => { 
3024   it("maps the value", () => { 
3026       gMonthDayCanonicalMap({ 
3038       gMonthDayCanonicalMap({ 
3045         timezoneOffset: undefined, 
3050       gMonthDayCanonicalMap({ 
3057         timezoneOffset: 840, 
3062       gMonthDayCanonicalMap({ 
3069         timezoneOffset: undefined, 
3075   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
3076     assertThrows(() => { 
3077       gMonthDayCanonicalMap(0); 
3079     assertThrows(() => { 
3080       gMonthDayCanonicalMap("--01-01Z"); 
3082     assertThrows(() => { 
3083       gMonthDayCanonicalMap({ 
3094   it("throws an error if the value is not a complete gMonthDay value", () => { 
3095     assertThrows(() => { 
3096       gMonthDayCanonicalMap({}); 
3098     assertThrows(() => { 
3099       gMonthDayCanonicalMap({ 
3109     assertThrows(() => { 
3110       gMonthDayCanonicalMap({ year: 1972, month: 12, day: 31 }); 
3112     assertThrows(() => { 
3113       gMonthDayCanonicalMap({ day: 31 }); 
3118 describe("gDayCanonicalMap", () => { 
3119   it("maps the value", () => { 
3140         timezoneOffset: undefined, 
3152         timezoneOffset: 840, 
3164         timezoneOffset: undefined, 
3170   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
3171     assertThrows(() => { 
3172       gDayCanonicalMap(0); 
3174     assertThrows(() => { 
3175       gDayCanonicalMap("---01Z"); 
3177     assertThrows(() => { 
3189   it("throws an error if the value is not a complete gDay value", () => { 
3190     assertThrows(() => { 
3191       gDayCanonicalMap({}); 
3193     assertThrows(() => { 
3204     assertThrows(() => { 
3205       gDayCanonicalMap({ year: 1972, month: 12, day: 31 }); 
3210 describe("gMonthCanonicalMap", () => { 
3211   it("maps the value", () => { 
3213       gMonthCanonicalMap({ 
3225       gMonthCanonicalMap({ 
3232         timezoneOffset: undefined, 
3237       gMonthCanonicalMap({ 
3244         timezoneOffset: 840, 
3249       gMonthCanonicalMap({ 
3256         timezoneOffset: undefined, 
3262   it("throws an error if the value is not a date/timeSevenPropertyModel value", () => { 
3263     assertThrows(() => { 
3264       gMonthCanonicalMap(0); 
3266     assertThrows(() => { 
3267       gMonthCanonicalMap("--01Z"); 
3269     assertThrows(() => { 
3270       gMonthCanonicalMap({ 
3281   it("throws an error if the value is not a complete gMonth value", () => { 
3282     assertThrows(() => { 
3283       gMonthCanonicalMap({}); 
3285     assertThrows(() => { 
3286       gMonthCanonicalMap({ 
3296     assertThrows(() => { 
3297       gMonthCanonicalMap({ year: 1972, month: 12, day: 31 }); 
3302 describe("stringLexicalMap", () => { 
3303   it("maps the value", () => { 
3304     assertStrictEquals(stringLexicalMap(""), ""); 
3305     assertStrictEquals(stringLexicalMap("etaoin"), "etaoin"); 
3308   it("throws an error if the value is not a string", () => { 
3309     assertThrows(() => { 
3310       stringLexicalMap({}); 
3312     assertThrows(() => { 
3313       stringLexicalMap(0); 
3315     assertThrows(() => { 
3316       stringLexicalMap(new String()); 
3321 describe("booleanLexicalMap", () => { 
3322   it("maps the value", () => { 
3323     assertStrictEquals(booleanLexicalMap("0"), false); 
3324     assertStrictEquals(booleanLexicalMap("false"), false); 
3325     assertStrictEquals(booleanLexicalMap("1"), true); 
3326     assertStrictEquals(booleanLexicalMap("true"), true); 
3329   it("throws an error if the value is not a string", () => { 
3330     assertThrows(() => { 
3331       booleanLexicalMap({}); 
3333     assertThrows(() => { 
3334       booleanLexicalMap(0); 
3336     assertThrows(() => { 
3337       booleanLexicalMap(false); 
3342 describe("stringCanonicalMap", () => { 
3343   it("maps the value", () => { 
3344     assertStrictEquals(stringCanonicalMap(""), ""); 
3345     assertStrictEquals(stringCanonicalMap("etaoin"), "etaoin"); 
3348   it("throws an error if the value is not a string", () => { 
3349     assertThrows(() => { 
3350       stringCanonicalMap({}); 
3352     assertThrows(() => { 
3353       stringCanonicalMap(0); 
3355     assertThrows(() => { 
3356       stringCanonicalMap(new String()); 
3361 describe("booleanCanonicalMap", () => { 
3362   it("maps the value", () => { 
3363     assertStrictEquals(booleanCanonicalMap(false), "false"); 
3364     assertStrictEquals(booleanCanonicalMap(true), "true"); 
3367   it("throws an error if the value is not a boolean", () => { 
3368     assertThrows(() => { 
3369       booleanCanonicalMap({}); 
3371     assertThrows(() => { 
3372       booleanCanonicalMap(0); 
3374     assertThrows(() => { 
3375       booleanCanonicalMap("false"); 
3377     assertThrows(() => { 
3378       booleanCanonicalMap(new Boolean()); 
3383 describe("hexBinaryMap", () => { 
3384   it("maps the value", () => { 
3386       new Uint8Array(hexBinaryMap("")), 
3390       new Uint8Array(hexBinaryMap("4b494249")), 
3391       new Uint8Array([75, 73, 66, 73]), 
3394       new Uint8Array(hexBinaryMap("626173653634")), 
3395       new Uint8Array([98, 97, 115, 101, 54, 52]), 
3398       new Uint8Array(hexBinaryMap("14FB9C03D97E")), 
3399       new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9, 0x7E]), 
3403   it("throws an error if the value is not a string", () => { 
3404     assertThrows(() => { 
3407     assertThrows(() => { 
3410     assertThrows(() => { 
3411       hexBinaryMap(new ArrayBuffer()); 
3415   it("throws an error if the value is not a valid hexBinary", () => { 
3416     assertThrows(() => { 
3419     assertThrows(() => { 
3425 describe("hexBinaryCanonical", () => { 
3426   it("maps the value", () => { 
3428       hexBinaryCanonical(new ArrayBuffer()), 
3432       hexBinaryCanonical(new Uint8Array([75, 73, 66, 73]).buffer
), 
3437         new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
, 
3443         new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9, 0x7E]).buffer
, 
3449   it("throws an error if the value is not an array buffer", () => { 
3450     assertThrows(() => { 
3451       hexBinaryCanonical({}); 
3453     assertThrows(() => { 
3454       hexBinaryCanonical(0); 
3456     assertThrows(() => { 
3457       hexBinaryCanonical(""); 
3459     assertThrows(() => { 
3460       hexBinaryCanonical(new Uint8Array([]));