@cellaware/utils 3.2.23 → 3.3.23
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/dist/azure/cosmos.d.ts +12 -12
- package/dist/azure/cosmos.js +71 -12
- package/dist/util.d.ts +8 -6
- package/dist/util.js +27 -12
- package/package.json +1 -1
package/dist/azure/cosmos.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
12
|
-
export declare
|
|
1
|
+
export declare function getCosmosCurrentYear(timeZone?: string): string;
|
|
2
|
+
export declare function getCosmosTimestampYear(timeZone?: string): string;
|
|
3
|
+
export declare function getCosmosCurrentMonth(timeZone?: string): string;
|
|
4
|
+
export declare function getCosmosTimestampMonth(timeZone?: string): string;
|
|
5
|
+
export declare function getCosmosCurrentDay(timeZone?: string): string;
|
|
6
|
+
export declare function getCosmosTimestampDay(timeZone?: string): string;
|
|
7
|
+
export declare function getCosmosTimestampHour(timeZone?: string): string;
|
|
8
|
+
export declare function getCosmosTimestampMinute(timeZone?: string): string;
|
|
9
|
+
export declare function getCosmosTimestampSecond(timeZone?: string): string;
|
|
10
|
+
export declare function getCosmosCurrentDayWhereClause(timeZone?: string): string;
|
|
11
|
+
export declare function getCosmosCurrentMonthWhereClause(timeZone?: string): string;
|
|
12
|
+
export declare function getCosmosCurrentYearWhereClause(timeZone?: string): string;
|
|
13
13
|
export declare function cosmosSelect(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
|
|
14
14
|
export declare function cosmosInsert(databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
|
|
15
15
|
export declare function cosmosDelete(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<boolean>;
|
package/dist/azure/cosmos.js
CHANGED
|
@@ -1,16 +1,75 @@
|
|
|
1
1
|
import { CosmosClient } from '@azure/cosmos';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { isDaylightSavingTime } from '../util.js';
|
|
3
|
+
const COSMOS_CURRENT_DATETIME = `GetCurrentDateTime()`;
|
|
4
|
+
const COSMOS_TIMESTAMP_DATETIME = `TimestampToDateTime(c._ts*1000)`;
|
|
5
|
+
/**
|
|
6
|
+
* All Cosmos timestamps are UTC.
|
|
7
|
+
*/
|
|
8
|
+
function getCosmosTimeZoneHourDiff(timeZone) {
|
|
9
|
+
let diff = 0;
|
|
10
|
+
if (!!timeZone) {
|
|
11
|
+
const dst = isDaylightSavingTime(timeZone);
|
|
12
|
+
switch (timeZone) {
|
|
13
|
+
case 'America/New_York':
|
|
14
|
+
diff = dst ? -4 : -5;
|
|
15
|
+
break;
|
|
16
|
+
case 'America/Chicago':
|
|
17
|
+
diff = dst ? -5 : -6;
|
|
18
|
+
break;
|
|
19
|
+
case 'America/Denver':
|
|
20
|
+
diff = dst ? -6 : -7;
|
|
21
|
+
break;
|
|
22
|
+
case 'America/Los_Angeles':
|
|
23
|
+
diff = dst ? -7 : -8;
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return diff;
|
|
30
|
+
}
|
|
31
|
+
function getCosmosCurrentDateTime(timeZone) {
|
|
32
|
+
return `DateTimeAdd("hh", ${getCosmosTimeZoneHourDiff(timeZone)}, ${COSMOS_CURRENT_DATETIME})`;
|
|
33
|
+
}
|
|
34
|
+
function getCosmosTimestampDateTime(timeZone) {
|
|
35
|
+
return `DateTimeAdd("hh", ${getCosmosTimeZoneHourDiff(timeZone)}, ${COSMOS_TIMESTAMP_DATETIME})`;
|
|
36
|
+
}
|
|
37
|
+
export function getCosmosCurrentYear(timeZone) {
|
|
38
|
+
return `DateTimePart('yyyy', ${getCosmosCurrentDateTime(timeZone)})`;
|
|
39
|
+
}
|
|
40
|
+
export function getCosmosTimestampYear(timeZone) {
|
|
41
|
+
return `DateTimePart('yyyy', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
42
|
+
}
|
|
43
|
+
export function getCosmosCurrentMonth(timeZone) {
|
|
44
|
+
return `DateTimePart('mm', ${getCosmosCurrentDateTime(timeZone)})`;
|
|
45
|
+
}
|
|
46
|
+
export function getCosmosTimestampMonth(timeZone) {
|
|
47
|
+
return `DateTimePart('mm', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
48
|
+
}
|
|
49
|
+
export function getCosmosCurrentDay(timeZone) {
|
|
50
|
+
return `DateTimePart('dd', ${getCosmosCurrentDateTime(timeZone)})`;
|
|
51
|
+
}
|
|
52
|
+
export function getCosmosTimestampDay(timeZone) {
|
|
53
|
+
return `DateTimePart('dd', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
54
|
+
}
|
|
55
|
+
export function getCosmosTimestampHour(timeZone) {
|
|
56
|
+
return `DateTimePart('hh', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
57
|
+
}
|
|
58
|
+
export function getCosmosTimestampMinute(timeZone) {
|
|
59
|
+
return `DateTimePart('mi', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
60
|
+
}
|
|
61
|
+
export function getCosmosTimestampSecond(timeZone) {
|
|
62
|
+
return `DateTimePart('ss', ${getCosmosTimestampDateTime(timeZone)})`;
|
|
63
|
+
}
|
|
64
|
+
export function getCosmosCurrentDayWhereClause(timeZone) {
|
|
65
|
+
return `DateTimeDiff('dd', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
|
|
66
|
+
}
|
|
67
|
+
export function getCosmosCurrentMonthWhereClause(timeZone) {
|
|
68
|
+
return `DateTimeDiff('mm', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
|
|
69
|
+
}
|
|
70
|
+
export function getCosmosCurrentYearWhereClause(timeZone) {
|
|
71
|
+
return `DateTimeDiff('yyyy', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
|
|
72
|
+
}
|
|
14
73
|
export async function cosmosSelect(databaseId, collectionId, partitionKey, query) {
|
|
15
74
|
try {
|
|
16
75
|
const cosmosClient = new CosmosClient({
|
package/dist/util.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare function sleep(ms: number): Promise<any>;
|
|
2
2
|
export declare function removeMarkdownIndicators(input: string): string;
|
|
3
3
|
export declare function removePrefixIndicators(input: string, prefixes: string[]): string;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
4
|
+
export declare function initDate(timeZone?: string): Date;
|
|
5
|
+
export declare function isDaylightSavingTime(timeZone?: string): boolean;
|
|
6
|
+
export declare function isLeapYear(timeZone?: string): boolean;
|
|
7
|
+
export declare function getDaysInMonth(timeZone?: string): number;
|
|
8
|
+
export declare function getCurrentDayInMonth(timeZone?: string): number;
|
|
9
|
+
export declare function getDaysInYear(timeZone?: string): 366 | 365;
|
|
10
|
+
export declare function getCurrentMonth(timeZone?: string): number;
|
|
11
|
+
export declare function getCurrentYear(timeZone?: string): number;
|
package/dist/util.js
CHANGED
|
@@ -22,28 +22,43 @@ export function removePrefixIndicators(input, prefixes) {
|
|
|
22
22
|
}
|
|
23
23
|
return output;
|
|
24
24
|
}
|
|
25
|
-
export function
|
|
26
|
-
|
|
25
|
+
export function initDate(timeZone) {
|
|
26
|
+
const date = new Date();
|
|
27
|
+
if (!!timeZone) {
|
|
28
|
+
return new Date(date.toLocaleString('en-US', { timeZone }));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return date;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function isDaylightSavingTime(timeZone) {
|
|
35
|
+
const date = initDate(timeZone);
|
|
36
|
+
const jan = new Date(date.getFullYear(), 0, 1);
|
|
37
|
+
const jul = new Date(date.getFullYear(), 6, 1);
|
|
38
|
+
return date.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
|
|
39
|
+
}
|
|
40
|
+
export function isLeapYear(timeZone) {
|
|
41
|
+
let year = initDate(timeZone).getFullYear();
|
|
27
42
|
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
|
|
28
43
|
}
|
|
29
|
-
export function getDaysInMonth() {
|
|
30
|
-
let date =
|
|
44
|
+
export function getDaysInMonth(timeZone) {
|
|
45
|
+
let date = initDate(timeZone);
|
|
31
46
|
// NOTE: month is 0-based.
|
|
32
47
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
33
48
|
}
|
|
34
|
-
export function getCurrentDayInMonth() {
|
|
35
|
-
let date =
|
|
49
|
+
export function getCurrentDayInMonth(timeZone) {
|
|
50
|
+
let date = initDate(timeZone);
|
|
36
51
|
return date.getDate();
|
|
37
52
|
}
|
|
38
|
-
export function getDaysInYear() {
|
|
39
|
-
return isLeapYear() ? 366 : 365;
|
|
53
|
+
export function getDaysInYear(timeZone) {
|
|
54
|
+
return isLeapYear(timeZone) ? 366 : 365;
|
|
40
55
|
}
|
|
41
|
-
export function getCurrentMonth() {
|
|
42
|
-
let date =
|
|
56
|
+
export function getCurrentMonth(timeZone) {
|
|
57
|
+
let date = initDate(timeZone);
|
|
43
58
|
// NOTE: month is 0-based.
|
|
44
59
|
return date.getMonth() + 1;
|
|
45
60
|
}
|
|
46
|
-
export function getCurrentYear() {
|
|
47
|
-
let date =
|
|
61
|
+
export function getCurrentYear(timeZone) {
|
|
62
|
+
let date = initDate(timeZone);
|
|
48
63
|
return date.getFullYear();
|
|
49
64
|
}
|