Now.plainTimeISO.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. describe("correct behavior", () => {
  2. test("length is 0", () => {
  3. expect(Temporal.Now.plainTimeISO).toHaveLength(0);
  4. });
  5. test("basic functionality", () => {
  6. const plainTime = Temporal.Now.plainTimeISO();
  7. expect(plainTime).toBeInstanceOf(Temporal.PlainTime);
  8. expect(plainTime.calendar.id).toBe("iso8601");
  9. });
  10. test("custom time zone", () => {
  11. const timeZone = {
  12. getOffsetNanosecondsFor() {
  13. return 86399999999999;
  14. },
  15. };
  16. const plainTime = Temporal.Now.plainTimeISO("UTC");
  17. const plainTimeWithOffset = Temporal.Now.plainTimeISO(timeZone);
  18. // FIXME: Compare these in a sensible way
  19. });
  20. test("cannot have a time zone with more than a day", () => {
  21. [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
  22. const timeZone = {
  23. getOffsetNanosecondsFor() {
  24. return offset;
  25. },
  26. };
  27. expect(() => Temporal.Now.plainTimeISO(timeZone)).toThrowWithMessage(
  28. RangeError,
  29. "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
  30. );
  31. });
  32. });
  33. });
  34. describe("errors", () => {
  35. test("custom time zone doesn't have a getOffsetNanosecondsFor function", () => {
  36. expect(() => {
  37. Temporal.Now.plainTimeISO({});
  38. }).toThrowWithMessage(TypeError, "getOffsetNanosecondsFor is undefined");
  39. });
  40. });