-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add Temporal support to escape #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
720fd26
Add Temporal support to escape
pdeveltere b9088a8
Merge branch 'main' into feat/temporal-escape
wellwelwel 0345f37
refactor: use native Temporal types and cover the ISO fallback
pdeveltere 9053242
refactor: simplify temporalToString with structural narrowing
pdeveltere b82ca06
refactor: remove comments entirely, in line with codebase
pdeveltere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { Temporal as TemporalPolyfill } from '@js-temporal/polyfill'; | ||
| import { assert, test } from 'poku'; | ||
| import { escape } from '../src/index.ts'; | ||
|
|
||
| /** | ||
| * Uses the polyfill on runtimes without a Temporal global so these always run | ||
| * @todo remove this, and the @js-temporal/polyfill library, once node version 26 is lts (it is "current" for now) | ||
| */ | ||
| const Temporal = globalThis.Temporal ?? TemporalPolyfill; | ||
|
|
||
| test('Temporal.Instant is escaped like a Date', () => { | ||
| const instant = Temporal.Instant.from('2012-05-07T11:42:03.002Z'); | ||
|
|
||
| assert.strictEqual(escape(instant, false, 'Z'), "'2012-05-07 11:42:03.002'"); | ||
| }); | ||
|
|
||
| test('Temporal.Instant honors the time zone argument', () => { | ||
| const instant = Temporal.Instant.from('2012-05-07T11:42:03.002Z'); | ||
|
|
||
| assert.strictEqual( | ||
| escape(instant, false, '+0200'), | ||
| "'2012-05-07 13:42:03.002'" | ||
| ); | ||
| }); | ||
|
|
||
| test('Temporal.ZonedDateTime is escaped as an absolute time', () => { | ||
| const zoned = Temporal.Instant.from( | ||
| '2012-05-07T11:42:03.002Z' | ||
| ).toZonedDateTimeISO('+02:00'); | ||
|
|
||
| assert.strictEqual(escape(zoned, false, 'Z'), "'2012-05-07 11:42:03.002'"); | ||
| }); | ||
|
|
||
| test('Temporal.PlainDateTime is escaped ignoring the time zone', () => { | ||
| const plain = Temporal.PlainDateTime.from('2012-05-07T11:42:03.002'); | ||
|
|
||
| assert.strictEqual( | ||
| escape(plain, false, '+0200'), | ||
| "'2012-05-07 11:42:03.002'" | ||
| ); | ||
| }); | ||
|
|
||
| test('Temporal.PlainDate is escaped as a DATE literal', () => { | ||
| assert.strictEqual( | ||
| escape(Temporal.PlainDate.from('2012-05-07')), | ||
| "'2012-05-07'" | ||
| ); | ||
| }); | ||
|
|
||
| test('Temporal.PlainTime is escaped as a TIME literal', () => { | ||
| assert.strictEqual(escape(Temporal.PlainTime.from('11:42:03')), "'11:42:03'"); | ||
| }); | ||
|
|
||
| test('Temporal types without a MySQL equivalent fall back to their ISO string', () => { | ||
| assert.strictEqual( | ||
| escape(Temporal.Duration.from({ hours: 2, minutes: 30 })), | ||
| "'PT2H30M'" | ||
| ); | ||
| assert.strictEqual( | ||
| escape(Temporal.PlainYearMonth.from('2012-05')), | ||
| "'2012-05'" | ||
| ); | ||
| assert.strictEqual(escape(Temporal.PlainMonthDay.from('05-07')), "'05-07'"); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.