Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,30 @@ function getOffsetFromZoneId (timeZoneId, epochSecond, nanosecond) {
return offset
}

const dateTimeFormatCache = new Map();

function getDateTimeFormatForZoneId(timeZoneId) {
if (!dateTimeFormatCache.has(timeZoneId)) {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: timeZoneId,
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
era: 'narrow'
})

dateTimeFormatCache.set(timeZoneId, formatter)
}

return dateTimeFormatCache.get(timeZoneId)
}

function getTimeInZoneId (timeZoneId, epochSecond, nano) {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: timeZoneId,
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
era: 'narrow'
})
const formatter = getDateTimeFormatForZoneId(timeZoneId)

const utc = int(epochSecond)
.multiply(1000)
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/internal/temporal-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,20 @@ export function assertValidNanosecond (
)
}

export function assertValidZoneId (fieldName: string, zoneId: string): void {
const timeZoneValidityCache = new Map();

export function assertValidZoneId(fieldName: string, zoneId: string): void {
let result = false;

try {
Intl.DateTimeFormat(undefined, { timeZone: zoneId })
if (timeZoneValidityCache.get(zoneId)) return;
Comment thread
bigmontz marked this conversation as resolved.
Outdated
result = !!Intl.DateTimeFormat(undefined, { timeZone: zoneId });
Comment thread
bigmontz marked this conversation as resolved.
Outdated
} catch (e) {
throw newError(
`${fieldName} is expected to be a valid ZoneId but was: "${zoneId}"`
)
);
} finally {
timeZoneValidityCache.set(zoneId, result)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,30 @@ function getOffsetFromZoneId (timeZoneId, epochSecond, nanosecond) {
return offset
}

const dateTimeFormatCache = new Map();

function getDateTimeFormatForZoneId(timeZoneId) {
if (!dateTimeFormatCache.has(timeZoneId)) {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: timeZoneId,
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
era: 'narrow'
})

dateTimeFormatCache.set(timeZoneId, formatter)
}

return dateTimeFormatCache.get(timeZoneId)
}

function getTimeInZoneId (timeZoneId, epochSecond, nano) {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: timeZoneId,
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
era: 'narrow'
})
const formatter = getDateTimeFormatForZoneId(timeZoneId)

const utc = int(epochSecond)
.multiply(1000)
Expand Down
13 changes: 10 additions & 3 deletions packages/neo4j-driver-deno/lib/core/internal/temporal-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,20 @@ export function assertValidNanosecond (
)
}

export function assertValidZoneId (fieldName: string, zoneId: string): void {
const timeZoneValidityCache = new Map();

export function assertValidZoneId(fieldName: string, zoneId: string): void {
let result = false

try {
Intl.DateTimeFormat(undefined, { timeZone: zoneId })
if (timeZoneValidityCache.get(zoneId)) return
result = !!Intl.DateTimeFormat(undefined, { timeZone: zoneId })
} catch (e) {
throw newError(
`${fieldName} is expected to be a valid ZoneId but was: "${zoneId}"`
)
);
} finally {
timeZoneValidityCache.set(zoneId, result)
}
}

Expand Down
26 changes: 26 additions & 0 deletions runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
npm install -g gulp typescript jest

npm ci
npm run build -- --no-private

if [ -n "$2" ]; then
export NEOCTRL_ARGS="$2"
fi

trap "npm run stop-neo4j" EXIT

npm run start-neo4j

if [ $? -ne 0 ]; then
echo "Unable to start neo4j"
exit 1
fi

npm test -- --no-private

if [ $? -eq 0 ]; then
echo "Exit with code 0"
else
echo "Exit with code 1"
exit 1
fi