@osdk/client 2.6.0-beta.2 → 2.6.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/browser/object/formatting/applyPropertyFormatter.js +7 -1
- package/build/browser/object/formatting/applyPropertyFormatter.js.map +1 -1
- package/build/browser/object/formatting/applyPropertyFormatter.test.js +305 -2
- package/build/browser/object/formatting/applyPropertyFormatter.test.js.map +1 -1
- package/build/browser/object/formatting/formatDateTime.js +158 -0
- package/build/browser/object/formatting/formatDateTime.js.map +1 -0
- package/build/browser/util/UserAgent.js +2 -2
- package/build/cjs/{chunk-X7WMWKLM.cjs → chunk-BRYZR53E.cjs} +142 -5
- package/build/cjs/chunk-BRYZR53E.cjs.map +1 -0
- package/build/cjs/index.cjs +7 -7
- package/build/cjs/public/unstable-do-not-use.cjs +6 -6
- package/build/esm/object/formatting/applyPropertyFormatter.js +7 -1
- package/build/esm/object/formatting/applyPropertyFormatter.js.map +1 -1
- package/build/esm/object/formatting/applyPropertyFormatter.test.js +305 -2
- package/build/esm/object/formatting/applyPropertyFormatter.test.js.map +1 -1
- package/build/esm/object/formatting/formatDateTime.js +158 -0
- package/build/esm/object/formatting/formatDateTime.js.map +1 -0
- package/build/esm/util/UserAgent.js +2 -2
- package/build/types/object/formatting/applyPropertyFormatter.d.ts.map +1 -1
- package/build/types/object/formatting/formatDateTime.d.ts +6 -0
- package/build/types/object/formatting/formatDateTime.d.ts.map +1 -0
- package/package.json +6 -6
- package/build/cjs/chunk-X7WMWKLM.cjs.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { resolvePropertyReference } from "./propertyFormattingUtils.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Formats a date/timestamp value according to the specified formatting rule
|
|
21
|
+
*/
|
|
22
|
+
export function formatDateTime(value, format, timezone, objectData, locale, userTimezoneOverride) {
|
|
23
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
24
|
+
if (isNaN(date.getTime())) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const resolvedTimezone = resolveTimezone(timezone, objectData, userTimezoneOverride);
|
|
28
|
+
switch (format.type) {
|
|
29
|
+
case "localizedFormat":
|
|
30
|
+
return formatLocalized(date, format, locale, resolvedTimezone);
|
|
31
|
+
case "stringFormat":
|
|
32
|
+
// TODO - pattern formatting
|
|
33
|
+
return undefined;
|
|
34
|
+
default:
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const INVALID_DATE_STRING = "Invalid date or timezone";
|
|
39
|
+
function formatLocalized(date, format, locale, timezone) {
|
|
40
|
+
if (format.format === "DATE_FORMAT_ISO_INSTANT") {
|
|
41
|
+
return date.toISOString();
|
|
42
|
+
}
|
|
43
|
+
if (format.format === "DATE_FORMAT_RELATIVE_TO_NOW") {
|
|
44
|
+
return formatRelativeToNow(date, locale, timezone);
|
|
45
|
+
}
|
|
46
|
+
const options = getLocalizedFormatOptions(format.format);
|
|
47
|
+
try {
|
|
48
|
+
return new Intl.DateTimeFormat(locale, timezone ? {
|
|
49
|
+
...options,
|
|
50
|
+
timeZone: timezone
|
|
51
|
+
} : options).format(date);
|
|
52
|
+
} catch (_e) {
|
|
53
|
+
// If a property reference is an invalid timezone we specifically say that it's invalid instead of returning undefined;
|
|
54
|
+
return INVALID_DATE_STRING;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function getLocalizedFormatOptions(format) {
|
|
58
|
+
switch (format) {
|
|
59
|
+
case "DATE_FORMAT_DATE":
|
|
60
|
+
return FORMAT_DATE;
|
|
61
|
+
case "DATE_FORMAT_YEAR_AND_MONTH":
|
|
62
|
+
return FORMAT_YEAR_AND_MONTH;
|
|
63
|
+
case "DATE_FORMAT_DATE_TIME":
|
|
64
|
+
return FORMAT_DATE_TIME;
|
|
65
|
+
case "DATE_FORMAT_DATE_TIME_SHORT":
|
|
66
|
+
return FORMAT_DATE_TIME_SHORT;
|
|
67
|
+
case "DATE_FORMAT_TIME":
|
|
68
|
+
return FORMAT_TIME;
|
|
69
|
+
default:
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const FORMAT_DATE = {
|
|
74
|
+
day: "numeric",
|
|
75
|
+
month: "short",
|
|
76
|
+
weekday: "short",
|
|
77
|
+
year: "numeric"
|
|
78
|
+
};
|
|
79
|
+
const FORMAT_YEAR_AND_MONTH = {
|
|
80
|
+
month: "short",
|
|
81
|
+
year: "numeric"
|
|
82
|
+
};
|
|
83
|
+
const FORMAT_DATE_TIME = {
|
|
84
|
+
day: "numeric",
|
|
85
|
+
month: "short",
|
|
86
|
+
weekday: "short",
|
|
87
|
+
year: "numeric",
|
|
88
|
+
hour: "numeric",
|
|
89
|
+
minute: "numeric",
|
|
90
|
+
second: "numeric"
|
|
91
|
+
};
|
|
92
|
+
const FORMAT_DATE_TIME_SHORT = {
|
|
93
|
+
day: "numeric",
|
|
94
|
+
month: "short",
|
|
95
|
+
year: "numeric",
|
|
96
|
+
hour: "numeric",
|
|
97
|
+
minute: "numeric"
|
|
98
|
+
};
|
|
99
|
+
const FORMAT_TIME = {
|
|
100
|
+
hour: "numeric",
|
|
101
|
+
minute: "numeric",
|
|
102
|
+
second: "numeric"
|
|
103
|
+
};
|
|
104
|
+
const DATE_TIME_SHORT_WITH_WEEKDAY = {
|
|
105
|
+
day: "numeric",
|
|
106
|
+
month: "short",
|
|
107
|
+
weekday: "short",
|
|
108
|
+
year: "numeric",
|
|
109
|
+
hour: "numeric",
|
|
110
|
+
minute: "numeric"
|
|
111
|
+
};
|
|
112
|
+
function resolveTimezone(timezone, objectData, userTimezoneOverride) {
|
|
113
|
+
if (userTimezoneOverride != null) {
|
|
114
|
+
return userTimezoneOverride;
|
|
115
|
+
}
|
|
116
|
+
if (timezone == null) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
switch (timezone.type) {
|
|
120
|
+
case "user":
|
|
121
|
+
return undefined;
|
|
122
|
+
case "static":
|
|
123
|
+
return resolvePropertyReference(timezone.zoneId, objectData);
|
|
124
|
+
default:
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const SECOND_MS = 1_000;
|
|
129
|
+
const MINUTE_MS = 60 * SECOND_MS;
|
|
130
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
131
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
132
|
+
function formatRelativeToNow(date, locale, timezone) {
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
const diff = date.valueOf() - now;
|
|
135
|
+
const absDiff = Math.abs(diff);
|
|
136
|
+
|
|
137
|
+
// More than 1 day - fall back to absolute date formatting
|
|
138
|
+
if (absDiff >= DAY_MS) {
|
|
139
|
+
const dtf = new Intl.DateTimeFormat(locale, {
|
|
140
|
+
...DATE_TIME_SHORT_WITH_WEEKDAY,
|
|
141
|
+
timeZone: timezone
|
|
142
|
+
});
|
|
143
|
+
return dtf.format(date);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Within 1 day - use relative formatting
|
|
147
|
+
const rtf = new Intl.RelativeTimeFormat(locale, {
|
|
148
|
+
numeric: "auto"
|
|
149
|
+
});
|
|
150
|
+
const units = [["hour", HOUR_MS], ["minute", MINUTE_MS], ["second", SECOND_MS]];
|
|
151
|
+
for (const [unit, ms] of units) {
|
|
152
|
+
if (absDiff >= ms) {
|
|
153
|
+
return rtf.format(Math.floor(diff / ms), unit);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return rtf.format(0, "second");
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=formatDateTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatDateTime.js","names":["resolvePropertyReference","formatDateTime","value","format","timezone","objectData","locale","userTimezoneOverride","date","Date","isNaN","getTime","undefined","resolvedTimezone","resolveTimezone","type","formatLocalized","INVALID_DATE_STRING","toISOString","formatRelativeToNow","options","getLocalizedFormatOptions","Intl","DateTimeFormat","timeZone","_e","FORMAT_DATE","FORMAT_YEAR_AND_MONTH","FORMAT_DATE_TIME","FORMAT_DATE_TIME_SHORT","FORMAT_TIME","day","month","weekday","year","hour","minute","second","DATE_TIME_SHORT_WITH_WEEKDAY","zoneId","SECOND_MS","MINUTE_MS","HOUR_MS","DAY_MS","now","diff","valueOf","absDiff","Math","abs","dtf","rtf","RelativeTimeFormat","numeric","units","unit","ms","floor"],"sources":["formatDateTime.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DatetimeFormat,\n DatetimeLocalizedFormat,\n DatetimeTimezone,\n} from \"@osdk/api\";\nimport type { DatetimeLocalizedFormatType } from \"@osdk/foundry.ontologies\";\nimport type { SimpleOsdkProperties } from \"../SimpleOsdkProperties.js\";\nimport { resolvePropertyReference } from \"./propertyFormattingUtils.js\";\n\n/**\n * Formats a date/timestamp value according to the specified formatting rule\n */\nexport function formatDateTime(\n value: Date,\n format: DatetimeFormat,\n timezone: DatetimeTimezone | undefined,\n objectData: SimpleOsdkProperties,\n locale: string,\n userTimezoneOverride?: string,\n): string | undefined {\n const date = value instanceof Date ? value : new Date(value);\n if (isNaN(date.getTime())) {\n return undefined;\n }\n\n const resolvedTimezone = resolveTimezone(\n timezone,\n objectData,\n userTimezoneOverride,\n );\n\n switch (format.type) {\n case \"localizedFormat\":\n return formatLocalized(date, format, locale, resolvedTimezone);\n case \"stringFormat\":\n // TODO - pattern formatting\n return undefined;\n default:\n format satisfies never;\n return undefined;\n }\n}\n\nconst INVALID_DATE_STRING = \"Invalid date or timezone\";\n\nfunction formatLocalized(\n date: Date,\n format: DatetimeLocalizedFormat,\n locale: string,\n timezone: string | undefined,\n): string | undefined {\n if (format.format === \"DATE_FORMAT_ISO_INSTANT\") {\n return date.toISOString();\n }\n if (format.format === \"DATE_FORMAT_RELATIVE_TO_NOW\") {\n return formatRelativeToNow(date, locale, timezone);\n }\n\n const options = getLocalizedFormatOptions(format.format);\n try {\n return new Intl.DateTimeFormat(\n locale,\n timezone ? { ...options, timeZone: timezone } : options,\n ).format(date);\n } catch (_e) {\n // If a property reference is an invalid timezone we specifically say that it's invalid instead of returning undefined;\n return INVALID_DATE_STRING;\n }\n}\n\nfunction getLocalizedFormatOptions(\n format: Exclude<\n DatetimeLocalizedFormatType,\n \"DATE_FORMAT_RELATIVE_TO_NOW\" | \"DATE_FORMAT_ISO_INSTANT\"\n >,\n): Intl.DateTimeFormatOptions {\n switch (format) {\n case \"DATE_FORMAT_DATE\":\n return FORMAT_DATE;\n\n case \"DATE_FORMAT_YEAR_AND_MONTH\":\n return FORMAT_YEAR_AND_MONTH;\n\n case \"DATE_FORMAT_DATE_TIME\":\n return FORMAT_DATE_TIME;\n\n case \"DATE_FORMAT_DATE_TIME_SHORT\":\n return FORMAT_DATE_TIME_SHORT;\n\n case \"DATE_FORMAT_TIME\":\n return FORMAT_TIME;\n\n default:\n format satisfies never;\n return {};\n }\n}\n\nconst FORMAT_DATE: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"short\",\n weekday: \"short\",\n year: \"numeric\",\n};\n\nconst FORMAT_YEAR_AND_MONTH: Intl.DateTimeFormatOptions = {\n month: \"short\",\n year: \"numeric\",\n};\n\nconst FORMAT_DATE_TIME: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"short\",\n weekday: \"short\",\n year: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n};\n\nconst FORMAT_DATE_TIME_SHORT: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"short\",\n year: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n};\n\nconst FORMAT_TIME: Intl.DateTimeFormatOptions = {\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n};\n\nconst DATE_TIME_SHORT_WITH_WEEKDAY: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"short\",\n weekday: \"short\",\n year: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n};\n\nfunction resolveTimezone(\n timezone: DatetimeTimezone | undefined,\n objectData: SimpleOsdkProperties,\n userTimezoneOverride?: string,\n): string | undefined {\n if (userTimezoneOverride != null) {\n return userTimezoneOverride;\n }\n if (timezone == null) {\n return undefined;\n }\n\n switch (timezone.type) {\n case \"user\":\n return undefined;\n case \"static\":\n return resolvePropertyReference(timezone.zoneId, objectData);\n default:\n timezone satisfies never;\n return undefined;\n }\n}\n\nconst SECOND_MS = 1_000;\nconst MINUTE_MS = 60 * SECOND_MS;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nfunction formatRelativeToNow(\n date: Date,\n locale: string,\n timezone: string | undefined,\n): string {\n const now = Date.now();\n const diff = date.valueOf() - now;\n const absDiff = Math.abs(diff);\n\n // More than 1 day - fall back to absolute date formatting\n if (absDiff >= DAY_MS) {\n const dtf = new Intl.DateTimeFormat(locale, {\n ...DATE_TIME_SHORT_WITH_WEEKDAY,\n timeZone: timezone,\n });\n return dtf.format(date);\n }\n\n // Within 1 day - use relative formatting\n const rtf = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\" });\n\n const units: [Intl.RelativeTimeFormatUnit, number][] = [\n [\"hour\", HOUR_MS],\n [\"minute\", MINUTE_MS],\n [\"second\", SECOND_MS],\n ];\n\n for (const [unit, ms] of units) {\n if (absDiff >= ms) {\n return rtf.format(Math.floor(diff / ms), unit);\n }\n }\n return rtf.format(0, \"second\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,wBAAwB,QAAQ,8BAA8B;;AAEvE;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC5BC,KAAW,EACXC,MAAsB,EACtBC,QAAsC,EACtCC,UAAgC,EAChCC,MAAc,EACdC,oBAA6B,EACT;EACpB,MAAMC,IAAI,GAAGN,KAAK,YAAYO,IAAI,GAAGP,KAAK,GAAG,IAAIO,IAAI,CAACP,KAAK,CAAC;EAC5D,IAAIQ,KAAK,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE;IACzB,OAAOC,SAAS;EAClB;EAEA,MAAMC,gBAAgB,GAAGC,eAAe,CACtCV,QAAQ,EACRC,UAAU,EACVE,oBACF,CAAC;EAED,QAAQJ,MAAM,CAACY,IAAI;IACjB,KAAK,iBAAiB;MACpB,OAAOC,eAAe,CAACR,IAAI,EAAEL,MAAM,EAAEG,MAAM,EAAEO,gBAAgB,CAAC;IAChE,KAAK,cAAc;MACjB;MACA,OAAOD,SAAS;IAClB;MAEE,OAAOA,SAAS;EACpB;AACF;AAEA,MAAMK,mBAAm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AMwC,GAAG,GAAGnC,IAAI,CAACmC,GAAG,CAAC,CAAC;EACtB,MAAMC,IAAI,GAAGrC,IAAI,CAACsC,OAAO,CAAC,CAAC,GAAGF,GAAG;EACjC,MAAMG,OAAO,GAAGC,IAAI,CAACC,GAAG,CAACJ,IAAI,CAAC;;EAE9B;EACA,IAAIE,OAAO,IAAIJ,MAAM,EAAE;IACrB,MAAMO,GAAG,GAAG,IAAI5B,IAAI,CAACC,cAAc,CAACjB,MAAM,EAAE;MAC1C,GAAGgC,4BAA4B;MAC/Bd,QAAQ,EAAEpB;IACZ,CAAC,CAAC;IACF,OAAO8C,GAAG,CAAC/C,MAAM,CAACK,IAAI,CAAC;EACzB;;EAEA;EACA,MAAM2C,GAAG,GAAG,IAAI7B,IAAI,CAAC8B,kBAAkB,CAAC9C,MAAM,EAAE;IAAE+C,OAAO,EAAE;EAAO,CAAC,CAAC;EAEpE,MAAMC,KAA8C,GAAG,CACrD,CAAC,MAAM,EAAEZ,OAAO,CAAC,EACjB,CAAC,QAAQ,EAAED,SAAS,CAAC,EACrB,CAAC,QAAQ,EAAED,SAAS,CAAC,CACtB;EAED,KAAK,MAAM,CAACe,IAAI,EAAEC,EAAE,CAAC,IAAIF,KAAK,EAAE;IAC9B,IAAIP,OAAO,IAAIS,EAAE,EAAE;MACjB,OAAOL,GAAG,CAAChD,MAAM,CAAC6C,IAAI,CAACS,KAAK,CAACZ,IAAI,GAAGW,EAAE,CAAC,EAAED,IAAI,CAAC;IAChD;EACF;EACA,OAAOJ,GAAG,CAAChD,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC;AAChC","ignoreList":[]}
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
export const USER_AGENT = `osdk-client/${"2.6.0-beta.
|
|
18
|
-
export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.
|
|
17
|
+
export const USER_AGENT = `osdk-client/${"2.6.0-beta.3"}`;
|
|
18
|
+
export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.3"}`;
|
|
19
19
|
//# sourceMappingURL=UserAgent.js.map
|
|
@@ -839,6 +839,138 @@ function getBrowserLocale() {
|
|
|
839
839
|
return "en-US";
|
|
840
840
|
}
|
|
841
841
|
|
|
842
|
+
// src/object/formatting/formatDateTime.ts
|
|
843
|
+
function formatDateTime(value, format, timezone, objectData, locale, userTimezoneOverride) {
|
|
844
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
845
|
+
if (isNaN(date.getTime())) {
|
|
846
|
+
return void 0;
|
|
847
|
+
}
|
|
848
|
+
const resolvedTimezone = resolveTimezone(timezone, objectData, userTimezoneOverride);
|
|
849
|
+
switch (format.type) {
|
|
850
|
+
case "localizedFormat":
|
|
851
|
+
return formatLocalized(date, format, locale, resolvedTimezone);
|
|
852
|
+
case "stringFormat":
|
|
853
|
+
return void 0;
|
|
854
|
+
default:
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
var INVALID_DATE_STRING = "Invalid date or timezone";
|
|
859
|
+
function formatLocalized(date, format, locale, timezone) {
|
|
860
|
+
if (format.format === "DATE_FORMAT_ISO_INSTANT") {
|
|
861
|
+
return date.toISOString();
|
|
862
|
+
}
|
|
863
|
+
if (format.format === "DATE_FORMAT_RELATIVE_TO_NOW") {
|
|
864
|
+
return formatRelativeToNow(date, locale, timezone);
|
|
865
|
+
}
|
|
866
|
+
const options = getLocalizedFormatOptions(format.format);
|
|
867
|
+
try {
|
|
868
|
+
return new Intl.DateTimeFormat(locale, timezone ? {
|
|
869
|
+
...options,
|
|
870
|
+
timeZone: timezone
|
|
871
|
+
} : options).format(date);
|
|
872
|
+
} catch (_e) {
|
|
873
|
+
return INVALID_DATE_STRING;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function getLocalizedFormatOptions(format) {
|
|
877
|
+
switch (format) {
|
|
878
|
+
case "DATE_FORMAT_DATE":
|
|
879
|
+
return FORMAT_DATE;
|
|
880
|
+
case "DATE_FORMAT_YEAR_AND_MONTH":
|
|
881
|
+
return FORMAT_YEAR_AND_MONTH;
|
|
882
|
+
case "DATE_FORMAT_DATE_TIME":
|
|
883
|
+
return FORMAT_DATE_TIME;
|
|
884
|
+
case "DATE_FORMAT_DATE_TIME_SHORT":
|
|
885
|
+
return FORMAT_DATE_TIME_SHORT;
|
|
886
|
+
case "DATE_FORMAT_TIME":
|
|
887
|
+
return FORMAT_TIME;
|
|
888
|
+
default:
|
|
889
|
+
return {};
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
var FORMAT_DATE = {
|
|
893
|
+
day: "numeric",
|
|
894
|
+
month: "short",
|
|
895
|
+
weekday: "short",
|
|
896
|
+
year: "numeric"
|
|
897
|
+
};
|
|
898
|
+
var FORMAT_YEAR_AND_MONTH = {
|
|
899
|
+
month: "short",
|
|
900
|
+
year: "numeric"
|
|
901
|
+
};
|
|
902
|
+
var FORMAT_DATE_TIME = {
|
|
903
|
+
day: "numeric",
|
|
904
|
+
month: "short",
|
|
905
|
+
weekday: "short",
|
|
906
|
+
year: "numeric",
|
|
907
|
+
hour: "numeric",
|
|
908
|
+
minute: "numeric",
|
|
909
|
+
second: "numeric"
|
|
910
|
+
};
|
|
911
|
+
var FORMAT_DATE_TIME_SHORT = {
|
|
912
|
+
day: "numeric",
|
|
913
|
+
month: "short",
|
|
914
|
+
year: "numeric",
|
|
915
|
+
hour: "numeric",
|
|
916
|
+
minute: "numeric"
|
|
917
|
+
};
|
|
918
|
+
var FORMAT_TIME = {
|
|
919
|
+
hour: "numeric",
|
|
920
|
+
minute: "numeric",
|
|
921
|
+
second: "numeric"
|
|
922
|
+
};
|
|
923
|
+
var DATE_TIME_SHORT_WITH_WEEKDAY = {
|
|
924
|
+
day: "numeric",
|
|
925
|
+
month: "short",
|
|
926
|
+
weekday: "short",
|
|
927
|
+
year: "numeric",
|
|
928
|
+
hour: "numeric",
|
|
929
|
+
minute: "numeric"
|
|
930
|
+
};
|
|
931
|
+
function resolveTimezone(timezone, objectData, userTimezoneOverride) {
|
|
932
|
+
if (userTimezoneOverride != null) {
|
|
933
|
+
return userTimezoneOverride;
|
|
934
|
+
}
|
|
935
|
+
if (timezone == null) {
|
|
936
|
+
return void 0;
|
|
937
|
+
}
|
|
938
|
+
switch (timezone.type) {
|
|
939
|
+
case "user":
|
|
940
|
+
return void 0;
|
|
941
|
+
case "static":
|
|
942
|
+
return resolvePropertyReference(timezone.zoneId, objectData);
|
|
943
|
+
default:
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
var SECOND_MS = 1e3;
|
|
948
|
+
var MINUTE_MS = 60 * SECOND_MS;
|
|
949
|
+
var HOUR_MS = 60 * MINUTE_MS;
|
|
950
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
951
|
+
function formatRelativeToNow(date, locale, timezone) {
|
|
952
|
+
const now = Date.now();
|
|
953
|
+
const diff = date.valueOf() - now;
|
|
954
|
+
const absDiff = Math.abs(diff);
|
|
955
|
+
if (absDiff >= DAY_MS) {
|
|
956
|
+
const dtf = new Intl.DateTimeFormat(locale, {
|
|
957
|
+
...DATE_TIME_SHORT_WITH_WEEKDAY,
|
|
958
|
+
timeZone: timezone
|
|
959
|
+
});
|
|
960
|
+
return dtf.format(date);
|
|
961
|
+
}
|
|
962
|
+
const rtf = new Intl.RelativeTimeFormat(locale, {
|
|
963
|
+
numeric: "auto"
|
|
964
|
+
});
|
|
965
|
+
const units = [["hour", HOUR_MS], ["minute", MINUTE_MS], ["second", SECOND_MS]];
|
|
966
|
+
for (const [unit, ms] of units) {
|
|
967
|
+
if (absDiff >= ms) {
|
|
968
|
+
return rtf.format(Math.floor(diff / ms), unit);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return rtf.format(0, "second");
|
|
972
|
+
}
|
|
973
|
+
|
|
842
974
|
// src/object/formatting/formatNumber.ts
|
|
843
975
|
function formatNumber(value, numberType, objectData, locale) {
|
|
844
976
|
switch (numberType.type) {
|
|
@@ -1042,7 +1174,12 @@ function formatPropertyValue(value, rule, objectData, options) {
|
|
|
1042
1174
|
return void 0;
|
|
1043
1175
|
}
|
|
1044
1176
|
return formatNumber(value, rule.numberType, objectData, options.locale ?? getBrowserLocale());
|
|
1045
|
-
|
|
1177
|
+
case "date":
|
|
1178
|
+
case "timestamp":
|
|
1179
|
+
if (typeof value !== "string") {
|
|
1180
|
+
return void 0;
|
|
1181
|
+
}
|
|
1182
|
+
return formatDateTime(new Date(value), rule.format, rule.type === "timestamp" ? rule.displayTimezone : void 0, objectData, options.locale ?? getBrowserLocale(), options.timezoneId);
|
|
1046
1183
|
default:
|
|
1047
1184
|
return void 0;
|
|
1048
1185
|
}
|
|
@@ -1639,8 +1776,8 @@ var createStandardOntologyProviderFactory = (client) => {
|
|
|
1639
1776
|
};
|
|
1640
1777
|
|
|
1641
1778
|
// src/util/UserAgent.ts
|
|
1642
|
-
var USER_AGENT = `osdk-client/${"2.6.0-beta.
|
|
1643
|
-
var OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.
|
|
1779
|
+
var USER_AGENT = `osdk-client/${"2.6.0-beta.3"}`;
|
|
1780
|
+
var OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.3"}`;
|
|
1644
1781
|
|
|
1645
1782
|
// src/createMinimalClient.ts
|
|
1646
1783
|
function createMinimalClient(metadata, baseUrl, tokenProvider, options = {}, fetchFn = global.fetch, objectSetFactory = chunk6L3MX4LH_cjs.createObjectSet, createOntologyProviderFactory = createStandardOntologyProviderFactory) {
|
|
@@ -2164,5 +2301,5 @@ exports.createClientFromContext = createClientFromContext;
|
|
|
2164
2301
|
exports.createClientWithTransaction = createClientWithTransaction;
|
|
2165
2302
|
exports.createObjectSpecifierFromPrimaryKey = createObjectSpecifierFromPrimaryKey;
|
|
2166
2303
|
exports.extractPrimaryKeyFromObjectSpecifier = extractPrimaryKeyFromObjectSpecifier;
|
|
2167
|
-
//# sourceMappingURL=chunk-
|
|
2168
|
-
//# sourceMappingURL=chunk-
|
|
2304
|
+
//# sourceMappingURL=chunk-BRYZR53E.cjs.map
|
|
2305
|
+
//# sourceMappingURL=chunk-BRYZR53E.cjs.map
|