From 3485ba8e1c12af6bded72e707e05a69af848d7ed Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Thu, 19 Dec 2024 13:16:29 +0100 Subject: [PATCH] fix(hog): not now (#27051) --- hogvm/__tests__/__snapshots__/stl.hoge | 19 ++++++++++--------- hogvm/__tests__/__snapshots__/stl.js | 18 ++++++++++++++++-- hogvm/__tests__/__snapshots__/stl.stdout | 3 ++- hogvm/__tests__/stl.hog | 5 +++-- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/hogvm/__tests__/__snapshots__/stl.hoge b/hogvm/__tests__/__snapshots__/stl.hoge index 27eec40d11d20..08000276db21c 100644 --- a/hogvm/__tests__/__snapshots__/stl.hoge +++ b/hogvm/__tests__/__snapshots__/stl.hoge @@ -47,17 +47,18 @@ "startsWith", 2, 32, "abcdef", 33, 2, 33, 3, 2, "substring", 3, 2, "print", 2, 35, 31, 31, 32, "firstNonNull", 2, "coalesce", 3, 32, "notNull", 2, "assumeNotNull", 1, 2, "print", 2, 35, 32, "", 2, "print", 1, 35, 32, "-- date --", 2, "print", 1, 35, 32, "2024-12-18T00:00:00Z", 2, "toDateTime", 1, 2, "toYear", 1, 32, "2024-12-18T00:00:00Z", 2, -"toDateTime", 1, 2, "toMonth", 1, 2, "print", 2, 35, 2, "now", 0, 2, "toStartOfDay", 1, 2, "now", 0, 2, "toStartOfWeek", -1, 2, "print", 2, 35, 32, "2024-12-18T00:00:00Z", 2, "toDateTime", 1, 2, "toYYYYMM", 1, 2, "print", 1, 35, 32, "day", -33, 1, 32, "2024-12-18", 2, "toDate", 1, 2, "dateAdd", 3, 32, "day", 32, "2024-12-18", 2, "toDate", 1, 32, "day", 33, 5, -32, "2024-12-18", 2, "toDate", 1, 2, "dateAdd", 3, 2, "dateDiff", 3, 2, "print", 2, 35, 32, "day", 32, +"toDateTime", 1, 2, "toMonth", 1, 2, "print", 2, 35, 2, "now", 0, 2, "typeof", 1, 2, "print", 1, 35, 32, +"2024-12-18T11:11:11Z", 2, "toDateTime", 1, 2, "toStartOfDay", 1, 32, "2024-12-18T11:11:11Z", 2, "toDateTime", 1, 2, +"toStartOfWeek", 1, 2, "print", 2, 35, 32, "2024-12-18T00:00:00Z", 2, "toDateTime", 1, 2, "toYYYYMM", 1, 2, "print", 1, +35, 32, "day", 33, 1, 32, "2024-12-18", 2, "toDate", 1, 2, "dateAdd", 3, 32, "day", 32, "2024-12-18", 2, "toDate", 1, +32, "day", 33, 5, 32, "2024-12-18", 2, "toDate", 1, 2, "dateAdd", 3, 2, "dateDiff", 3, 2, "print", 2, 35, 32, "day", 32, "2024-12-18T12:34:56Z", 2, "toDateTime", 1, 2, "dateTrunc", 2, 2, "print", 1, 35, 32, "2024-12-18", 2, "toDate", 1, 33, 3, 2, "addDays", 2, 2, "print", 1, 35, 33, 5, 2, "toIntervalDay", 1, 33, 2, 2, "toIntervalMonth", 1, 2, "print", 2, 35, -2, "today", 0, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- json --", 2, "print", 1, 35, 32, "{\"a\":123.1}", -32, "a", 2, "JSONExtractInt", 2, 2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, "JSONExtractInt", 2, 2, -"jsonStringify", 1, 2, "print", 2, 35, 32, "{\"a\":123.1}", 32, "a", 2, "JSONExtractFloat", 2, 2, "jsonStringify", 1, -32, "{\"a\":\"hello\"}", 32, "a", 2, "JSONExtractFloat", 2, 2, "jsonStringify", 1, 2, "print", 2, 35, 32, -"{\"a\":123.1}", 32, "a", 2, "JSONExtractString", 2, 2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, +2, "today", 0, 2, "typeof", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- json --", 2, "print", 1, 35, 32, +"{\"a\":123.1}", 32, "a", 2, "JSONExtractInt", 2, 2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, +"JSONExtractInt", 2, 2, "jsonStringify", 1, 2, "print", 2, 35, 32, "{\"a\":123.1}", 32, "a", 2, "JSONExtractFloat", 2, +2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, "JSONExtractFloat", 2, 2, "jsonStringify", 1, 2, "print", 2, +35, 32, "{\"a\":123.1}", 32, "a", 2, "JSONExtractString", 2, 2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, "JSONExtractString", 2, 2, "jsonStringify", 1, 2, "print", 2, 35, 32, "{\"a\":123}", 32, "a", 2, "JSONExtractArrayRaw", 2, 2, "jsonStringify", 1, 32, "{\"a\":\"hello\"}", 32, "a", 2, "JSONExtractArrayRaw", 2, 2, "jsonStringify", 1, 2, "print", 2, 35, 32, "{\"a\":[]}", 32, "a", 2, "JSONExtractArrayRaw", 2, 2, "jsonStringify", 1, 32, diff --git a/hogvm/__tests__/__snapshots__/stl.js b/hogvm/__tests__/__snapshots__/stl.js index b0d9fdd74a80e..247aa1ec4abed 100644 --- a/hogvm/__tests__/__snapshots__/stl.js +++ b/hogvm/__tests__/__snapshots__/stl.js @@ -1,4 +1,17 @@ function upper (value) { return value.toUpperCase() } +function __x_typeof (value) { + if (value === null || value === undefined) { return 'null' + } else if (__isHogDateTime(value)) { return 'datetime' + } else if (__isHogDate(value)) { return 'date' + } else if (__isHogError(value)) { return 'error' + } else if (typeof value === 'function') { return 'function' + } else if (Array.isArray(value)) { if (value.__isHogTuple) { return 'tuple' } return 'array' + } else if (typeof value === 'object') { return 'object' + } else if (typeof value === 'number') { return Number.isInteger(value) ? 'integer' : 'float' + } else if (typeof value === 'string') { return 'string' + } else if (typeof value === 'boolean') { return 'boolean' } + return 'unknown' +} function tuple (...args) { const tuple = args.slice(); tuple.__isHogTuple = true; return tuple; } function today() { const now = new Date(); @@ -522,13 +535,14 @@ print(coalesce(null, null, "firstNonNull"), assumeNotNull("notNull")); print(""); print("-- date --"); print(toYear(toDateTime("2024-12-18T00:00:00Z")), toMonth(toDateTime("2024-12-18T00:00:00Z"))); -print(toStartOfDay(now()), toStartOfWeek(now())); +print(__x_typeof(now())); +print(toStartOfDay(toDateTime("2024-12-18T11:11:11Z")), toStartOfWeek(toDateTime("2024-12-18T11:11:11Z"))); print(toYYYYMM(toDateTime("2024-12-18T00:00:00Z"))); print(dateAdd("day", 1, toDate("2024-12-18")), dateDiff("day", toDate("2024-12-18"), dateAdd("day", 5, toDate("2024-12-18")))); print(dateTrunc("day", toDateTime("2024-12-18T12:34:56Z"))); print(addDays(toDate("2024-12-18"), 3)); print(toIntervalDay(5), toIntervalMonth(2)); -print(today()); +print(__x_typeof(today())); print(""); print("-- json --"); print(jsonStringify(JSONExtractInt("{\"a\":123.1}", "a")), jsonStringify(JSONExtractInt("{\"a\":\"hello\"}", "a"))); diff --git a/hogvm/__tests__/__snapshots__/stl.stdout b/hogvm/__tests__/__snapshots__/stl.stdout index ed72feb96e789..b9f6eabbc5c82 100644 --- a/hogvm/__tests__/__snapshots__/stl.stdout +++ b/hogvm/__tests__/__snapshots__/stl.stdout @@ -93,13 +93,14 @@ firstNonNull notNull -- date -- 2024 12 +datetime DateTime(1734480000.0, 'UTC') DateTime(1734307200.0, 'UTC') 202412 Date(2024, 12, 19) 5 DateTime(1734480000.0, 'UTC') Date(2024, 12, 21) {'__hogInterval__': true, 'value': 5, 'unit': 'day'} {'__hogInterval__': true, 'value': 2, 'unit': 'month'} -Date(2024, 12, 18) +date -- json -- 123 null diff --git a/hogvm/__tests__/stl.hog b/hogvm/__tests__/stl.hog index 946880cc6163e..a00871f041b38 100644 --- a/hogvm/__tests__/stl.hog +++ b/hogvm/__tests__/stl.hog @@ -93,13 +93,14 @@ print(coalesce(null, null, 'firstNonNull'), assumeNotNull('notNull')) print('') print('-- date --') print(toYear(toDateTime('2024-12-18T00:00:00Z')), toMonth(toDateTime('2024-12-18T00:00:00Z'))) -print(toStartOfDay(now()), toStartOfWeek(now())) +print(typeof(now())) +print(toStartOfDay(toDateTime('2024-12-18T11:11:11Z')), toStartOfWeek(toDateTime('2024-12-18T11:11:11Z'))) print(toYYYYMM(toDateTime('2024-12-18T00:00:00Z'))) print(dateAdd('day', 1, toDate('2024-12-18')), dateDiff('day', toDate('2024-12-18'), dateAdd('day', 5, toDate('2024-12-18')))) print(dateTrunc('day', toDateTime('2024-12-18T12:34:56Z'))) print(addDays(toDate('2024-12-18'), 3)) print(toIntervalDay(5), toIntervalMonth(2)) -print(today()) +print(typeof(today())) print('') print('-- json --') print(jsonStringify(JSONExtractInt('{"a":123.1}', 'a')), jsonStringify(JSONExtractInt('{"a":"hello"}','a')))