Skip to content

Commit

Permalink
new formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Nov 18, 2024
1 parent 2a4ae09 commit 6699881
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 123 deletions.
6 changes: 3 additions & 3 deletions hogvm/__tests__/__snapshots__/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ let c = [1, 2, 3];
print(__getProperty(c, 1, false), __getProperty(c, 2, false), __getProperty(c, 3, false), __getProperty(c, 4, false));
print(__getProperty(c, -1, false), __getProperty(c, -2, false), __getProperty(c, -3, false), __getProperty(c, -4, false));
print("------");
print(["a", "b", "c"].includes("a"));
print(["a", "b", "c"].includes("d"));
print([].includes("a"));
print((["a", "b", "c"].includes("a")));
print((["a", "b", "c"].includes("d")));
print(([].includes("a")));
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -69,25 +69,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}
function NotImplementedError (message, payload) { return __newHogError('NotImplementedError', message, payload) }
function HogError (type, message, payload) { return __newHogError(type, message, payload) }
function __newHogError(type, message, payload) {
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/catch2.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -69,25 +69,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}
function HogError (type, message, payload) { return __newHogError(type, message, payload) }
function __newHogError(type, message, payload) {
let error = new Error(message || 'An error occurred');
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/dateFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -220,25 +220,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}

let dt = fromUnixTimestamp(1234377543.123456);
print(formatDateTime(dt, "%Y-%m-%d %H:%i:%S"));
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -61,25 +61,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}
function __x_Error (message, payload) { return __newHogError('Error', message, payload) }
function __newHogError(type, message, payload) {
let error = new Error(message || 'An error occurred');
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/mandelbrot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -61,25 +61,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}

function mandelbrot(re, im, max_iter) {
let z_re = 0.0;
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -113,25 +113,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}

function test(val) {
print(jsonStringify(val));
Expand Down
31 changes: 16 additions & 15 deletions hogvm/__tests__/__snapshots__/printLoops.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function __escapeIdentifier(identifier) {
}
function __isHogDateTime(obj) { return obj && obj.__hogDateTime__ === true }
function __isHogDate(obj) { return obj && obj.__hogDate__ === true }
function __DateTimeToString (dt) {
if (__isHogDateTime(dt)) {
function __DateTimeToString(dt) {
if (__isHogDateTime(dt)) {
const date = new Date(dt.dt * 1000);
const timeZone = dt.zone || 'UTC';
const milliseconds = Math.floor(dt.dt * 1000 % 1000);
Expand All @@ -126,25 +126,26 @@ function __DateTimeToString (dt) {
default: break;
}
}
const getOffset = (date, timeZone) => {
const tzDate = new Date(date.toLocaleString('en-US', { timeZone }));
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const offset = (tzDate - utcDate) / 60000; // in minutes
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const hours = Math.floor(absOffset / 60);
const minutes = absOffset % 60;
return `${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
};
let offset = 'Z';
if (timeZone !== 'UTC') {
const tzOptions = { timeZone, timeZoneName: 'shortOffset' };
const tzFormatter = new Intl.DateTimeFormat('en-US', tzOptions);
const tzParts = tzFormatter.formatToParts(date);
const timeZoneNamePart = tzParts.find(part => part.type === 'timeZoneName');
if (timeZoneNamePart && timeZoneNamePart.value) {
const offsetString = timeZoneNamePart.value;
const match = offsetString.match(/GMT([+-]\d{2})(?::?(\d{2}))?/);
offset = match ? `${match[1][0]}${match[1].slice(1).padStart(2, '0')}:${(match[2] || '00').padStart(2, '0')}` : offsetString === 'GMT' ? '+00:00' : '';
}
offset = getOffset(date, timeZone);
}
let isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
if (milliseconds !== null) {
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
}
isoString += `.${milliseconds.toString().padStart(3, '0')}`;
isoString += offset;
return isoString;
}}
}
}

let obj = {"key": "value", "key2": "value2"};
let str = "na";
Expand Down
Loading

0 comments on commit 6699881

Please sign in to comment.