@magmacomputing/tempo 1.0.0
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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/array.library.d.ts +25 -0
- package/dist/array.library.js +78 -0
- package/dist/buffer.library.d.ts +6 -0
- package/dist/buffer.library.js +192 -0
- package/dist/cipher.class.d.ts +18 -0
- package/dist/cipher.class.js +65 -0
- package/dist/class.library.d.ts +10 -0
- package/dist/class.library.js +57 -0
- package/dist/coercion.library.d.ts +14 -0
- package/dist/coercion.library.js +71 -0
- package/dist/enumerate.library.d.ts +64 -0
- package/dist/enumerate.library.js +54 -0
- package/dist/function.library.d.ts +9 -0
- package/dist/function.library.js +49 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/logify.class.d.ts +33 -0
- package/dist/logify.class.js +53 -0
- package/dist/number.library.d.ts +16 -0
- package/dist/number.library.js +36 -0
- package/dist/object.library.d.ts +37 -0
- package/dist/object.library.js +94 -0
- package/dist/pledge.class.d.ts +54 -0
- package/dist/pledge.class.js +131 -0
- package/dist/prototype.library.d.ts +33 -0
- package/dist/prototype.library.js +51 -0
- package/dist/reflection.library.d.ts +74 -0
- package/dist/reflection.library.js +97 -0
- package/dist/serialize.library.d.ts +25 -0
- package/dist/serialize.library.js +266 -0
- package/dist/storage.library.d.ts +8 -0
- package/dist/storage.library.js +57 -0
- package/dist/string.library.d.ts +37 -0
- package/dist/string.library.js +93 -0
- package/dist/tempo.class.d.ts +556 -0
- package/dist/tempo.class.js +1412 -0
- package/dist/tempo.config/plugins/term.import.d.ts +42 -0
- package/dist/tempo.config/plugins/term.import.js +44 -0
- package/dist/tempo.config/plugins/term.quarter.d.ts +7 -0
- package/dist/tempo.config/plugins/term.quarter.js +28 -0
- package/dist/tempo.config/plugins/term.season.d.ts +7 -0
- package/dist/tempo.config/plugins/term.season.js +36 -0
- package/dist/tempo.config/plugins/term.timeline.d.ts +7 -0
- package/dist/tempo.config/plugins/term.timeline.js +19 -0
- package/dist/tempo.config/plugins/term.utils.d.ts +17 -0
- package/dist/tempo.config/plugins/term.utils.js +38 -0
- package/dist/tempo.config/plugins/term.zodiac.d.ts +7 -0
- package/dist/tempo.config/plugins/term.zodiac.js +62 -0
- package/dist/tempo.config/tempo.default.d.ts +169 -0
- package/dist/tempo.config/tempo.default.js +158 -0
- package/dist/tempo.config/tempo.enum.d.ts +99 -0
- package/dist/tempo.config/tempo.enum.js +78 -0
- package/dist/temporal.polyfill.d.ts +9 -0
- package/dist/temporal.polyfill.js +18 -0
- package/dist/type.library.d.ts +296 -0
- package/dist/type.library.js +80 -0
- package/dist/utility.library.d.ts +32 -0
- package/dist/utility.library.js +54 -0
- package/package.json +54 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* import of plugins
|
|
3
|
+
*/
|
|
4
|
+
import * as qtr from '../../tempo.config/plugins/term.quarter.js';
|
|
5
|
+
declare const _default: {
|
|
6
|
+
key: string;
|
|
7
|
+
scope: string;
|
|
8
|
+
description: string;
|
|
9
|
+
define: typeof qtr.define;
|
|
10
|
+
}[];
|
|
11
|
+
export default _default;
|
|
12
|
+
/**
|
|
13
|
+
* Usage:
|
|
14
|
+
* show only the 'key' field from the pre-defined range
|
|
15
|
+
* new Tempo('20-May-1957').term.qtr # range of Fiscal Quarters
|
|
16
|
+
* > 'Q2'
|
|
17
|
+
* show the 'range' object that relates to the Tempo instance
|
|
18
|
+
* new Tempo('28-Aug-1968').term.quarter
|
|
19
|
+
* > {key: 'Q2', day: 1, month: 4, fiscal: 1969}
|
|
20
|
+
*
|
|
21
|
+
* Notes:
|
|
22
|
+
* A 'term' has two parts:
|
|
23
|
+
* 1) an array of objects that define the DateTime lower boundaries of a range
|
|
24
|
+
* (e.g. [{key: 'Summer', day: 1, month: 12}, {key: 'Autumn', day: 1, month: 3}...])
|
|
25
|
+
* these are statically defined when the Tempo class is first imported.
|
|
26
|
+
*
|
|
27
|
+
* 2) a function which determines where a Tempo instance fits within the above range array.
|
|
28
|
+
* this function is assigned to a getter on the 'term' property for each new Tempo instance.
|
|
29
|
+
*
|
|
30
|
+
* The 'export default' is an object that stashes the plugin definitions.
|
|
31
|
+
* Tempo will use this object to define getter properties on each instance (under the 'term' property).
|
|
32
|
+
* (for example, new Tempo().term.season)
|
|
33
|
+
* The getter will not execute the code until actually referenced (lazy-loaded).
|
|
34
|
+
* In this way, we can defer the execution of the lookup until it is needed
|
|
35
|
+
* and keep a Tempo instance as light-weight as possible.
|
|
36
|
+
*
|
|
37
|
+
* In addition, the getter will be auto-replaced with the return-value of the plugin definition.
|
|
38
|
+
* (for example, the
|
|
39
|
+
* Object.defineProperty(..., ..., { get: () => { ... } }) will be overridden after first access with
|
|
40
|
+
* Object.defineProperty(..., ..., { value: ... })
|
|
41
|
+
* In this way, we can memoize the result of the plugin definition, and avoid the need to execute the lookup again.
|
|
42
|
+
*/
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* import of plugins
|
|
3
|
+
*/
|
|
4
|
+
import * as qtr from '../../tempo.config/plugins/term.quarter.js';
|
|
5
|
+
import * as szn from '../../tempo.config/plugins/term.season.js';
|
|
6
|
+
import * as zdc from '../../tempo.config/plugins/term.zodiac.js';
|
|
7
|
+
import * as per from '../../tempo.config/plugins/term.timeline.js';
|
|
8
|
+
export default [
|
|
9
|
+
{ key: qtr.key, scope: qtr.scope, description: qtr.description, define: qtr.define },
|
|
10
|
+
{ key: szn.key, scope: szn.scope, description: szn.description, define: szn.define },
|
|
11
|
+
{ key: zdc.key, scope: zdc.scope, description: zdc.description, define: zdc.define },
|
|
12
|
+
{ key: per.key, scope: per.scope, description: per.description, define: per.define },
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Usage:
|
|
16
|
+
* show only the 'key' field from the pre-defined range
|
|
17
|
+
* new Tempo('20-May-1957').term.qtr # range of Fiscal Quarters
|
|
18
|
+
* > 'Q2'
|
|
19
|
+
* show the 'range' object that relates to the Tempo instance
|
|
20
|
+
* new Tempo('28-Aug-1968').term.quarter
|
|
21
|
+
* > {key: 'Q2', day: 1, month: 4, fiscal: 1969}
|
|
22
|
+
*
|
|
23
|
+
* Notes:
|
|
24
|
+
* A 'term' has two parts:
|
|
25
|
+
* 1) an array of objects that define the DateTime lower boundaries of a range
|
|
26
|
+
* (e.g. [{key: 'Summer', day: 1, month: 12}, {key: 'Autumn', day: 1, month: 3}...])
|
|
27
|
+
* these are statically defined when the Tempo class is first imported.
|
|
28
|
+
*
|
|
29
|
+
* 2) a function which determines where a Tempo instance fits within the above range array.
|
|
30
|
+
* this function is assigned to a getter on the 'term' property for each new Tempo instance.
|
|
31
|
+
*
|
|
32
|
+
* The 'export default' is an object that stashes the plugin definitions.
|
|
33
|
+
* Tempo will use this object to define getter properties on each instance (under the 'term' property).
|
|
34
|
+
* (for example, new Tempo().term.season)
|
|
35
|
+
* The getter will not execute the code until actually referenced (lazy-loaded).
|
|
36
|
+
* In this way, we can defer the execution of the lookup until it is needed
|
|
37
|
+
* and keep a Tempo instance as light-weight as possible.
|
|
38
|
+
*
|
|
39
|
+
* In addition, the getter will be auto-replaced with the return-value of the plugin definition.
|
|
40
|
+
* (for example, the
|
|
41
|
+
* Object.defineProperty(..., ..., { get: () => { ... } }) will be overridden after first access with
|
|
42
|
+
* Object.defineProperty(..., ..., { value: ... })
|
|
43
|
+
* In this way, we can memoize the result of the plugin definition, and avoid the need to execute the lookup again.
|
|
44
|
+
*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Range } from '../../tempo.config/plugins/term.utils.js';
|
|
2
|
+
import type { Tempo } from '../../tempo.class.js';
|
|
3
|
+
export declare const key = "qtr";
|
|
4
|
+
export declare const scope = "quarter";
|
|
5
|
+
export declare const description = "Fiscal Quarter";
|
|
6
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
7
|
+
export declare function define(this: Tempo, key?: boolean): PropertyKey | Range | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cloneify } from '../../serialize.library.js';
|
|
2
|
+
import { COMPASS } from '../../tempo.config/tempo.enum.js';
|
|
3
|
+
import { getTermRange } from '../../tempo.config/plugins/term.utils.js';
|
|
4
|
+
/** definition of fiscal quarter ranges */
|
|
5
|
+
const ranges = [
|
|
6
|
+
[
|
|
7
|
+
{ key: 'Q1', day: 1, month: 1, fiscal: 0, sphere: COMPASS.North },
|
|
8
|
+
{ key: 'Q2', day: 1, month: 4, fiscal: 0, sphere: COMPASS.North },
|
|
9
|
+
{ key: 'Q3', day: 1, month: 7, fiscal: 0, sphere: COMPASS.North },
|
|
10
|
+
{ key: 'Q4', day: 1, month: 10, fiscal: 0, sphere: COMPASS.North },
|
|
11
|
+
], [
|
|
12
|
+
{ key: 'Q1', day: 1, month: 7, fiscal: 1, sphere: COMPASS.South },
|
|
13
|
+
{ key: 'Q2', day: 1, month: 10, fiscal: 1, sphere: COMPASS.South },
|
|
14
|
+
{ key: 'Q3', day: 1, month: 1, fiscal: 0, sphere: COMPASS.South },
|
|
15
|
+
{ key: 'Q4', day: 1, month: 4, fiscal: 0, sphere: COMPASS.South },
|
|
16
|
+
]
|
|
17
|
+
];
|
|
18
|
+
export const key = 'qtr';
|
|
19
|
+
export const scope = 'quarter';
|
|
20
|
+
export const description = 'Fiscal Quarter';
|
|
21
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
22
|
+
export function define(key) {
|
|
23
|
+
const { yy, config: { sphere } } = this;
|
|
24
|
+
const south = sphere !== COMPASS.North; // false = North, true = South
|
|
25
|
+
const list = cloneify(ranges[+south]); // deep clone the range
|
|
26
|
+
list.forEach(itm => itm.fiscal += yy); // calc the fiscal-year for quarter
|
|
27
|
+
return getTermRange(this, list, key);
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Range } from '../../tempo.config/plugins/term.utils.js';
|
|
2
|
+
import type { Tempo } from '../../tempo.class.js';
|
|
3
|
+
export declare const key = "szn";
|
|
4
|
+
export declare const scope = "season";
|
|
5
|
+
export declare const description = "Meteorlogical season";
|
|
6
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
7
|
+
export declare function define(this: Tempo, keyOnly?: boolean): PropertyKey | Range | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cloneify } from '../../serialize.library.js';
|
|
2
|
+
import { COMPASS } from '../../tempo.config/tempo.enum.js';
|
|
3
|
+
import { getTermRange } from '../../tempo.config/plugins/term.utils.js';
|
|
4
|
+
/** definition of meteorological season ranges */
|
|
5
|
+
const ranges = [
|
|
6
|
+
[
|
|
7
|
+
{ key: 'Spring', day: 20, month: 3, symbol: 'Flower', sphere: COMPASS.North },
|
|
8
|
+
{ key: 'Summer', day: 21, month: 6, symbol: 'Sun', sphere: COMPASS.North },
|
|
9
|
+
{ key: 'Autumn', day: 23, month: 9, symbol: 'Leaf', sphere: COMPASS.North },
|
|
10
|
+
{ key: 'Winter', day: 22, month: 12, symbol: 'Snowflake', sphere: COMPASS.North },
|
|
11
|
+
], [
|
|
12
|
+
{ key: 'Spring', day: 1, month: 9, symbol: 'Flower', sphere: COMPASS.South },
|
|
13
|
+
{ key: 'Summer', day: 1, month: 12, symbol: 'Sun', sphere: COMPASS.South },
|
|
14
|
+
{ key: 'Autumn', day: 1, month: 3, symbol: 'Leaf', sphere: COMPASS.South },
|
|
15
|
+
{ key: 'Winter', day: 1, month: 6, symbol: 'Snowflake', sphere: COMPASS.South },
|
|
16
|
+
], [
|
|
17
|
+
{ key: 'Spring', day: 1, month: 3, symbol: 'Flower', trait: 'A time of renewal and growth' },
|
|
18
|
+
{ key: 'Summer', day: 1, month: 6, symbol: 'Sun', trait: 'A period of heat and fruition' },
|
|
19
|
+
{ key: 'Autumn', day: 1, month: 9, symbol: 'Leaf', trait: 'A time for harvest and contraction' },
|
|
20
|
+
{ key: 'Winter', day: 1, month: 12, symbol: 'Snowflake', trait: 'A period of stillness and consolidation' },
|
|
21
|
+
]
|
|
22
|
+
];
|
|
23
|
+
export const key = 'szn';
|
|
24
|
+
export const scope = 'season';
|
|
25
|
+
export const description = 'Meteorlogical season';
|
|
26
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
27
|
+
export function define(keyOnly) {
|
|
28
|
+
const { config: { sphere } } = this;
|
|
29
|
+
const south = sphere !== COMPASS.North; // false = North, true = South
|
|
30
|
+
const list = cloneify(ranges[+south]);
|
|
31
|
+
if (!keyOnly) {
|
|
32
|
+
const cn = getTermRange(this, ranges[2], false); // get the chinese season for the current day/month
|
|
33
|
+
list.forEach(item => item['CN'] = cn); // add the chinese season to each range item
|
|
34
|
+
}
|
|
35
|
+
return getTermRange(this, list, keyOnly);
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Range } from '../../tempo.config/plugins/term.utils.js';
|
|
2
|
+
import type { Tempo } from '../../tempo.class.js';
|
|
3
|
+
export declare const key = "per";
|
|
4
|
+
export declare const scope = "period";
|
|
5
|
+
export declare const description = "Daily time period";
|
|
6
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
7
|
+
export declare function define(this: Tempo, keyOnly?: boolean): PropertyKey | Range | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getTermRange } from '../../tempo.config/plugins/term.utils.js';
|
|
2
|
+
/** definition of daily time periods */
|
|
3
|
+
const ranges = [
|
|
4
|
+
{ key: 'midnight', hour: 0 },
|
|
5
|
+
{ key: 'early', hour: 4 },
|
|
6
|
+
{ key: 'morning', hour: 8 },
|
|
7
|
+
{ key: 'midmorning', hour: 10 },
|
|
8
|
+
{ key: 'midday', hour: 12 },
|
|
9
|
+
{ key: 'afternoon', hour: 15, minute: 30 },
|
|
10
|
+
{ key: 'evening', hour: 18 },
|
|
11
|
+
{ key: 'night', hour: 20 },
|
|
12
|
+
];
|
|
13
|
+
export const key = 'per';
|
|
14
|
+
export const scope = 'period';
|
|
15
|
+
export const description = 'Daily time period';
|
|
16
|
+
/** determine where the current Tempo instance fits within the above range */
|
|
17
|
+
export function define(keyOnly) {
|
|
18
|
+
return getTermRange(this, ranges, keyOnly);
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Tempo } from '../../tempo.class.js';
|
|
2
|
+
/** Tempo.Terms lets us know where a DateTime fits within pre-defined Ranges */
|
|
3
|
+
/** use this type to define a Range with a DateTime qualifier */
|
|
4
|
+
export type Range = {
|
|
5
|
+
key: PropertyKey;
|
|
6
|
+
year?: number;
|
|
7
|
+
month?: number;
|
|
8
|
+
day?: number;
|
|
9
|
+
hour?: number;
|
|
10
|
+
minute?: number;
|
|
11
|
+
second?: number;
|
|
12
|
+
[str: PropertyKey]: any;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* find where a Tempo fits within a range of DateTime
|
|
16
|
+
*/
|
|
17
|
+
export declare function getTermRange(tempo: Tempo, list: Range[], keyOnly?: boolean): PropertyKey | Range | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isDefined } from '../../type.library.js';
|
|
2
|
+
const SCHEMA = [
|
|
3
|
+
['year', 'yy'],
|
|
4
|
+
['month', 'mm'],
|
|
5
|
+
['day', 'dd'],
|
|
6
|
+
['hour', 'hh'],
|
|
7
|
+
['minute', 'mi'],
|
|
8
|
+
['second', 'ss'],
|
|
9
|
+
['millisecond', 'ms'],
|
|
10
|
+
['microsecond', 'us'],
|
|
11
|
+
['nanosecond', 'ns']
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* find where a Tempo fits within a range of DateTime
|
|
15
|
+
*/
|
|
16
|
+
export function getTermRange(tempo, list, keyOnly = true) {
|
|
17
|
+
const sorted = [...list]
|
|
18
|
+
.sortBy('year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond')
|
|
19
|
+
.toReversed();
|
|
20
|
+
const match = sorted
|
|
21
|
+
.find(range => {
|
|
22
|
+
for (const [rKey, sKey] of SCHEMA) {
|
|
23
|
+
const val = range[rKey];
|
|
24
|
+
if (isDefined(val)) {
|
|
25
|
+
const sVal = tempo[sKey];
|
|
26
|
+
if (sVal > val)
|
|
27
|
+
return true;
|
|
28
|
+
if (sVal < val)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return true; // fallback if DateTime exactly matches a range criteria
|
|
33
|
+
})
|
|
34
|
+
?? sorted.at(0); // fallback to wraparound at first item
|
|
35
|
+
return keyOnly
|
|
36
|
+
? match?.key
|
|
37
|
+
: match;
|
|
38
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Range } from '../../tempo.config/plugins/term.utils.js';
|
|
2
|
+
import type { Tempo } from '../../tempo.class.js';
|
|
3
|
+
export declare const key = "zdc";
|
|
4
|
+
export declare const scope = "zodiac";
|
|
5
|
+
export declare const description = "Astrological Zodiac sign";
|
|
6
|
+
/** determine where the current Tempo instance fits within the above ranges */
|
|
7
|
+
export declare function define(this: Tempo, keyOnly?: boolean): PropertyKey | Range | undefined;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { cloneify } from '../../serialize.library.js';
|
|
2
|
+
import { getTermRange } from '../../tempo.config/plugins/term.utils.js';
|
|
3
|
+
/** definition of astrological zodiac ranges */
|
|
4
|
+
const ranges = [
|
|
5
|
+
[
|
|
6
|
+
{ key: 'Aquarius', day: 20, month: 1, symbol: 'Ram', longitude: 300, planet: 'Uranus' },
|
|
7
|
+
{ key: 'Pisces', day: 19, month: 2, symbol: 'Fish', longitude: 330, planet: 'Neptune' },
|
|
8
|
+
{ key: 'Aries', day: 21, month: 3, symbol: 'Ram', longitude: 0, planet: 'Mars' },
|
|
9
|
+
{ key: 'Taurus', day: 20, month: 4, symbol: 'Bull', longitude: 30, planet: 'Venus' },
|
|
10
|
+
{ key: 'Gemini', day: 21, month: 5, symbol: 'Twins', longitude: 60, planet: 'Mercury' },
|
|
11
|
+
{ key: 'Cancer', day: 22, month: 6, symbol: 'Crab', longitude: 90, planet: 'Moon' },
|
|
12
|
+
{ key: 'Leo', day: 23, month: 7, symbol: 'Lion', longitude: 120, planet: 'Sun' },
|
|
13
|
+
{ key: 'Virgo', day: 23, month: 8, symbol: 'Maiden', longitude: 150, planet: 'Mercury' },
|
|
14
|
+
{ key: 'Libra', day: 23, month: 9, symbol: 'Scales', longitude: 180, planet: 'Venus' },
|
|
15
|
+
{ key: 'Scorpio', day: 23, month: 10, symbol: 'Scorpion', longitude: 210, planet: 'Pluto & Mars' },
|
|
16
|
+
{ key: 'Sagittarius', day: 22, month: 11, symbol: 'Centaur', longitude: 240, planet: 'Jupiter' },
|
|
17
|
+
{ key: 'Capricorn', day: 22, month: 12, symbol: 'Goat', longitude: 270, planet: 'Saturn' },
|
|
18
|
+
], [
|
|
19
|
+
{ key: 'Rat', traits: 'Adaptable, clever' },
|
|
20
|
+
{ key: 'Ox', traits: 'Diligent, strong' },
|
|
21
|
+
{ key: 'Tiger', traits: 'Passionate, courageous' },
|
|
22
|
+
{ key: 'Rabbit', traits: 'Artistic, gentle' },
|
|
23
|
+
{ key: 'Dragon', traits: 'Powerful, charismatic' },
|
|
24
|
+
{ key: 'Snake', traits: 'Wise, intuitive' },
|
|
25
|
+
{ key: 'Horse', traits: 'Energetic, independent' },
|
|
26
|
+
{ key: 'Goat', traits: 'Empathetic, calm' },
|
|
27
|
+
{ key: 'Monkey', traits: 'Smart, curious' },
|
|
28
|
+
{ key: 'Rooster', traits: 'Observant, hardworking' },
|
|
29
|
+
{ key: 'Dog', traits: 'Loyal, honest' },
|
|
30
|
+
{ key: 'Pig', traits: 'Compassionate, generous' },
|
|
31
|
+
], [
|
|
32
|
+
{ key: 'Wood' },
|
|
33
|
+
{ key: 'Fire' },
|
|
34
|
+
{ key: 'Earth' },
|
|
35
|
+
{ key: 'Metal' },
|
|
36
|
+
{ key: 'Water' },
|
|
37
|
+
]
|
|
38
|
+
];
|
|
39
|
+
export const key = 'zdc';
|
|
40
|
+
export const scope = 'zodiac';
|
|
41
|
+
export const description = 'Astrological Zodiac sign';
|
|
42
|
+
/** determine where the current Tempo instance fits within the above ranges */
|
|
43
|
+
export function define(keyOnly) {
|
|
44
|
+
const list = cloneify(ranges[0]); // make a copy of the ranges array
|
|
45
|
+
if (!keyOnly) {
|
|
46
|
+
const cn = getChineseZodiac(this.yy); // get the chinese zodiac for the current year
|
|
47
|
+
list.forEach(item => item['CN'] = cn); // add the chinese zodiac to each item
|
|
48
|
+
}
|
|
49
|
+
return getTermRange(this, list, keyOnly);
|
|
50
|
+
}
|
|
51
|
+
/** get the chinese zodiac for a given year */
|
|
52
|
+
function getChineseZodiac(year) {
|
|
53
|
+
const animalIndex = (year - 4) % 12; // calculate the animal index
|
|
54
|
+
const elementIndex = Math.floor(((year - 4) % 10) / 2); // calculate the element index based on the last digit of the year
|
|
55
|
+
const yinYang = year % 2 === 0 ? 'Yang' : 'Yin'; // determine Yin or Yang
|
|
56
|
+
return {
|
|
57
|
+
animal: ranges[1][animalIndex].key,
|
|
58
|
+
traits: ranges[1][animalIndex].traits,
|
|
59
|
+
element: ranges[2][elementIndex].key,
|
|
60
|
+
yinYang: yinYang
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Tempo } from '../tempo.class.js';
|
|
2
|
+
/** common RegExp patterns */
|
|
3
|
+
export declare const Match: {
|
|
4
|
+
/** match all {} pairs, if they start with a word char */ readonly braces: RegExp;
|
|
5
|
+
/** named capture-group, if it starts with a letter */ readonly captures: RegExp;
|
|
6
|
+
/** event */ readonly event: RegExp;
|
|
7
|
+
/** period */ readonly period: RegExp;
|
|
8
|
+
/** two digit year */ readonly twoDigit: RegExp;
|
|
9
|
+
/** hour-minute-second with no separator */ readonly hhmiss: RegExp;
|
|
10
|
+
/** separator characters (/ - . ,) */ readonly separator: RegExp;
|
|
11
|
+
/** modifier characters (+-<>=) */ readonly modifier: RegExp;
|
|
12
|
+
/** offset post keywords (ago|hence) */ readonly affix: RegExp;
|
|
13
|
+
/** strip out these characters from a string */ readonly strips: RegExp;
|
|
14
|
+
};
|
|
15
|
+
/** Tempo Symbol registry */
|
|
16
|
+
export declare const Token: import("../type.library.js").Extend<{
|
|
17
|
+
/** year */ readonly yy: symbol;
|
|
18
|
+
/** month */ readonly mm: symbol;
|
|
19
|
+
/** day */ readonly dd: symbol;
|
|
20
|
+
/** hour */ readonly hh: symbol;
|
|
21
|
+
/** minute */ readonly mi: symbol;
|
|
22
|
+
/** second */ readonly ss: symbol;
|
|
23
|
+
/** fraction */ readonly ff: symbol;
|
|
24
|
+
/** meridiem */ readonly mer: symbol;
|
|
25
|
+
/** short weekday name */ readonly www: symbol;
|
|
26
|
+
/** relative-suffix */ readonly afx: symbol;
|
|
27
|
+
/** time-suffix */ readonly sfx: symbol;
|
|
28
|
+
/** time unit */ readonly unt: symbol;
|
|
29
|
+
/** separator */ readonly sep: symbol;
|
|
30
|
+
/** modifier */ readonly mod: symbol;
|
|
31
|
+
/** generic number */ readonly nbr: symbol;
|
|
32
|
+
/** Tempo event */ readonly evt: symbol;
|
|
33
|
+
/** Tempo period */ readonly per: symbol;
|
|
34
|
+
/** time zone offset */ readonly tzd: symbol;
|
|
35
|
+
/** date */ readonly dt: symbol;
|
|
36
|
+
/** time */ readonly tm: symbol;
|
|
37
|
+
/** date and time */ readonly dtm: symbol;
|
|
38
|
+
/** day-month-year */ readonly dmy: symbol;
|
|
39
|
+
/** month-day-year */ readonly mdy: symbol;
|
|
40
|
+
/** year-month-day */ readonly ymd: symbol;
|
|
41
|
+
/** day of month offset */ readonly off: symbol;
|
|
42
|
+
/** weekDay */ readonly wkd: symbol;
|
|
43
|
+
/** relative offset (years, days, hours, etc) */ readonly rel: symbol;
|
|
44
|
+
}, string, symbol>;
|
|
45
|
+
export type Token = typeof Token;
|
|
46
|
+
/**
|
|
47
|
+
* user will need to know these in order to configure their own patterns
|
|
48
|
+
* Tempo.Snippet is a simple regex pattern object , e.g. { Symbol('yy'): /(([0-9]{2})?[0-9]{2})/ }
|
|
49
|
+
* Tempo.Layout is a string-combination of Snippet names , e.g. '{yy}{sep}{mm}({sep}{dd})?{sfx}?'
|
|
50
|
+
* Tempo.Pattern is a translation of a Layout/Snippets into an anchored regex.
|
|
51
|
+
* The {pattern} is used to parse a string | number in the Tempo constructor {DateTime} argument
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* a {snippet} is a simple, reusable regex pattern for a component of a date-time string (e.g. 'hh' or 'yy')
|
|
55
|
+
*/
|
|
56
|
+
export declare const Snippet: import("../type.library.js").Extend<{
|
|
57
|
+
readonly [Token.yy]: RegExp;
|
|
58
|
+
readonly [Token.mm]: RegExp;
|
|
59
|
+
readonly [Token.dd]: RegExp;
|
|
60
|
+
readonly [Token.hh]: RegExp;
|
|
61
|
+
readonly [Token.mi]: RegExp;
|
|
62
|
+
readonly [Token.ss]: RegExp;
|
|
63
|
+
readonly [Token.ff]: RegExp;
|
|
64
|
+
readonly [Token.mer]: RegExp;
|
|
65
|
+
readonly [Token.sfx]: RegExp;
|
|
66
|
+
readonly [Token.wkd]: RegExp;
|
|
67
|
+
readonly [Token.tzd]: RegExp;
|
|
68
|
+
readonly [Token.nbr]: RegExp;
|
|
69
|
+
readonly [Token.afx]: RegExp;
|
|
70
|
+
readonly [Token.mod]: RegExp;
|
|
71
|
+
readonly [Token.sep]: RegExp;
|
|
72
|
+
readonly [Token.unt]: RegExp;
|
|
73
|
+
}, symbol, RegExp>;
|
|
74
|
+
export type Snippet = typeof Snippet;
|
|
75
|
+
/**
|
|
76
|
+
* a {layout} is a Record of snippet-combinations describing an input DateTime argument
|
|
77
|
+
* the Layout's keys are in the order that they will be checked against an input value
|
|
78
|
+
*/
|
|
79
|
+
export declare const Layout: import("../type.library.js").Extend<{
|
|
80
|
+
readonly [Token.dt]: "{dd}{sep}?{mm}({sep}?{yy})?|{mod}?({evt})";
|
|
81
|
+
readonly [Token.tm]: "({hh}{mi}?{ss}?{ff}?{mer}?|{per})";
|
|
82
|
+
readonly [Token.dtm]: "({dt}){sfx}?";
|
|
83
|
+
readonly [Token.dmy]: "({wkd}{sep}+)?{dd}{sep}?{mm}({sep}?{yy})?{sfx}?";
|
|
84
|
+
readonly [Token.mdy]: "({wkd}{sep}+)?{mm}{sep}?{dd}({sep}?{yy})?{sfx}?";
|
|
85
|
+
readonly [Token.ymd]: "({wkd}{sep}+)?{yy}{sep}?{mm}({sep}?{dd})?{sfx}?";
|
|
86
|
+
readonly [Token.wkd]: "{mod}?{wkd}{afx}?{sfx}?";
|
|
87
|
+
readonly [Token.off]: "{mod}?{dd}{afx}?";
|
|
88
|
+
readonly [Token.rel]: "{nbr}{sep}?{unt}{sep}?{afx}";
|
|
89
|
+
}, symbol, string>;
|
|
90
|
+
export type Layout = typeof Layout;
|
|
91
|
+
/**
|
|
92
|
+
* an {event} is a Record of regex-pattern-like-string keys that describe Date strings.
|
|
93
|
+
* values can be a string or a function.
|
|
94
|
+
* if assigning a function, use standard 'function()' syntax to allow for 'this' binding.
|
|
95
|
+
* also, a function should always have a .toString() method which returns a parse-able Date string
|
|
96
|
+
*/
|
|
97
|
+
export declare const Event: import("../type.library.js").Extend<{
|
|
98
|
+
readonly 'new.?years? ?eve': "31 Dec";
|
|
99
|
+
readonly nye: "31 Dec";
|
|
100
|
+
readonly 'new.?years?( ?day)?': "01 Jan";
|
|
101
|
+
readonly ny: "01 Jan";
|
|
102
|
+
readonly 'christmas ?eve': "24 Dec";
|
|
103
|
+
readonly christmas: "25 Dec";
|
|
104
|
+
readonly 'xmas ?eve': "24 Dec";
|
|
105
|
+
readonly xmas: "25 Dec";
|
|
106
|
+
readonly now: (this: any) => Temporal.Instant;
|
|
107
|
+
readonly today: (this: any) => Temporal.PlainDate;
|
|
108
|
+
readonly tomorrow: (this: any) => Temporal.PlainDate;
|
|
109
|
+
readonly yesterday: (this: any) => Temporal.PlainDate;
|
|
110
|
+
}, string, string | Function>;
|
|
111
|
+
export type Event = typeof Event;
|
|
112
|
+
/**
|
|
113
|
+
* a {period} is a Record of regex-pattern-like keys that describe pre-defined Time strings.
|
|
114
|
+
* values can be a string or a function.
|
|
115
|
+
* if using a function, use regular 'function()' syntax to allow for 'this' binding.
|
|
116
|
+
*/
|
|
117
|
+
export declare const Period: import("../type.library.js").Extend<{
|
|
118
|
+
readonly 'mid[ -]?night': "24:00";
|
|
119
|
+
readonly morning: "8:00";
|
|
120
|
+
readonly 'mid[ -]?morning': "10:00";
|
|
121
|
+
readonly 'mid[ -]?day': "12:00";
|
|
122
|
+
readonly noon: "12:00";
|
|
123
|
+
readonly 'after[ -]?noon': "3:00pm";
|
|
124
|
+
readonly evening: "18:00";
|
|
125
|
+
readonly night: "20:00";
|
|
126
|
+
}, string, string | Function>;
|
|
127
|
+
export type Period = typeof Period;
|
|
128
|
+
/**
|
|
129
|
+
* a {timeZone} alias dictionary mapping common abbreviations to IANA strings.
|
|
130
|
+
* Tempo will check this registry to convert abbreviations before passing them to Temporal.
|
|
131
|
+
*/
|
|
132
|
+
export declare const TimeZone: import("../type.library.js").Extend<{
|
|
133
|
+
readonly utc: "UTC";
|
|
134
|
+
readonly gmt: "Europe/London";
|
|
135
|
+
readonly est: "America/New_York";
|
|
136
|
+
readonly cst: "America/Chicago";
|
|
137
|
+
readonly mst: "America/Denver";
|
|
138
|
+
readonly pst: "America/Los_Angeles";
|
|
139
|
+
readonly aest: "Australia/Sydney";
|
|
140
|
+
readonly acst: "Australia/Adelaide";
|
|
141
|
+
readonly awst: "Australia/Perth";
|
|
142
|
+
readonly nzt: "Pacific/Auckland";
|
|
143
|
+
readonly cet: "Europe/Paris";
|
|
144
|
+
readonly eet: "Europe/Helsinki";
|
|
145
|
+
readonly ist: "Asia/Kolkata";
|
|
146
|
+
readonly npt: "Asia/Kathmandu";
|
|
147
|
+
readonly jst: "Asia/Tokyo";
|
|
148
|
+
}, string, string>;
|
|
149
|
+
export type TimeZone = typeof TimeZone;
|
|
150
|
+
/** Reasonable default options for initial Tempo config */
|
|
151
|
+
export declare const Options: readonly ["value", "mdyLocales", "mdyLayouts", "store", "debug", "catch", "timeZone", "calendar", "locale", "pivot", "sphere", "timeStamp", "snippet", "layout", "event", "period"];
|
|
152
|
+
export declare const Default: import("../type.library.js").SecureObject<Partial<{
|
|
153
|
+
store: string;
|
|
154
|
+
debug: boolean | undefined;
|
|
155
|
+
catch: boolean | undefined;
|
|
156
|
+
timeZone: string;
|
|
157
|
+
calendar: string;
|
|
158
|
+
locale: string;
|
|
159
|
+
pivot: number;
|
|
160
|
+
sphere: Tempo.COMPASS | undefined;
|
|
161
|
+
timeStamp: Tempo.TimeStamp;
|
|
162
|
+
mdyLocales: string | string[];
|
|
163
|
+
mdyLayouts: [string, string][];
|
|
164
|
+
snippet: Snippet | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | /*elided*/ any)[])[])[])[])[])[])[])[])[])[])[]);
|
|
165
|
+
layout: Layout | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | (string | RegExp | Record<string | symbol, string | RegExp> | /*elided*/ any)[])[])[])[])[])[])[])[])[])[])[]);
|
|
166
|
+
event: Event | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | /*elided*/ any)[])[])[])[])[])[])[])[])[])[])[]);
|
|
167
|
+
period: Period | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | (string | Function | Record<string | symbol, string | Function> | /*elided*/ any)[])[])[])[])[])[])[])[])[])[])[]);
|
|
168
|
+
value: Tempo.DateTime;
|
|
169
|
+
}>>;
|