| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,6 +159,16 @@ function eq( | |||
| 159 | 159 | // RegExps are compared by their source patterns and flags. | |
| 160 | 160 | case '[object RegExp]': | |
| 161 | 161 | return a.source === b.source && a.flags === b.flags | |
| 162 | + case '[object Temporal.Instant]': | ||
| 163 | + case '[object Temporal.ZonedDateTime]': | ||
| 164 | + case '[object Temporal.PlainDateTime]': | ||
| 165 | + case '[object Temporal.PlainDate]': | ||
| 166 | + case '[object Temporal.PlainTime]': | ||
| 167 | + case '[object Temporal.PlainYearMonth]': | ||
| 168 | + case '[object Temporal.PlainMonthDay]': | ||
| 169 | + return a.equals(b) | ||
| 170 | + case '[object Temporal.Duration]': | ||
| 171 | + return a.toString() === b.toString() | ||
| 162 | 172 | } | |
| 163 | 173 | if (typeof a !== 'object' || typeof b !== 'object') { | |
| 164 | 174 | return false | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ | |||
| 30 | 30 | "react": "^19.1.0", | |
| 31 | 31 | "react-18": "npm:react@18.3.1", | |
| 32 | 32 | "sweetalert2": "^11.21.2", | |
| 33 | + "temporal-polyfill": "~0.3.0", | ||
| 33 | 34 | "tinyrainbow": "catalog:", | |
| 34 | 35 | "tinyspy": "^1.1.1", | |
| 35 | 36 | "url": "^0.11.4", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | import type { Tester } from '@vitest/expect' | |
| 2 | 2 | import { getCurrentTest } from '@vitest/runner' | |
| 3 | + import { Temporal } from 'temporal-polyfill' | ||
| 3 | 4 | import { describe, expect, expectTypeOf, test, vi } from 'vitest' | |
| 4 | 5 | ||
| 5 | 6 | describe('expect.soft', () => { | |
@@ -346,3 +347,45 @@ describe('iterator', () => { | |||
| 346 | 347 | expect(a).not.toStrictEqual(b) | |
| 347 | 348 | }) | |
| 348 | 349 | }) | |
| 350 | + | ||
| 351 | + describe('Temporal equality', () => { | ||
| 352 | + describe.each([ | ||
| 353 | + ['Instant', ['2025-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z']], | ||
| 354 | + ['ZonedDateTime', ['2025-01-01T00:00:00+01:00[Europe/Amsterdam]', '2025-01-01T00:00:00+01:00[Europe/Paris]']], | ||
| 355 | + ['PlainDateTime', ['2025-01-01T00:00:00.000', '2026-01-01T00:00:00.000']], | ||
| 356 | + ['PlainDate', ['2025-01-01', '2026-01-01']], | ||
| 357 | + ['PlainTime', ['15:00:00.000', '16:00:00.000']], | ||
| 358 | + ['PlainYearMonth', ['2025-01', '2026-01']], | ||
| 359 | + ['PlainMonthDay', ['01-01', '02-01']], | ||
| 360 | + ] as const)('of $className', (className, [first, second]) => { | ||
| 361 | + test('returns true when equal', () => { | ||
| 362 | + const a = Temporal[className].from(first) | ||
| 363 | + const b = Temporal[className].from(first) | ||
| 364 | + | ||
| 365 | + expect(a).toStrictEqual(b) | ||
| 366 | + }) | ||
| 367 | + | ||
| 368 | + test('returns false when not equal', () => { | ||
| 369 | + const a = Temporal[className].from(first) | ||
| 370 | + const b = Temporal[className].from(second) | ||
| 371 | + | ||
| 372 | + expect(a).not.toStrictEqual(b) | ||
| 373 | + }) | ||
| 374 | + }) | ||
| 375 | + | ||
| 376 | + describe('of Duration', () => { | ||
| 377 | + test('returns true when .toString() is equal', () => { | ||
| 378 | + const a = Temporal.Duration.from('P1M') | ||
| 379 | + const b = Temporal.Duration.from('P1M') | ||
| 380 | + | ||
| 381 | + expect(a).toStrictEqual(b) | ||
| 382 | + }) | ||
| 383 | + | ||
| 384 | + test('returns true when .toString() is not equal', () => { | ||
| 385 | + const a = Temporal.Duration.from('PT1M') | ||
| 386 | + const b = Temporal.Duration.from('PT60S') | ||
| 387 | + | ||
| 388 | + expect(a).not.toStrictEqual(b) | ||
| 389 | + }) | ||
| 390 | + }) | ||
| 391 | + }) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments