@tsdotnet/date-time 1.1.0 → 1.1.2

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.
Files changed (84) hide show
  1. package/dist/cjs/ClockTime.js +13 -18
  2. package/dist/cjs/ClockTime.js.map +1 -1
  3. package/dist/cjs/DateTime.js +9 -96
  4. package/dist/cjs/DateTime.js.map +1 -1
  5. package/dist/cjs/TimeQuantity.js +10 -43
  6. package/dist/cjs/TimeQuantity.js.map +1 -1
  7. package/dist/cjs/TimeSpan.js +5 -30
  8. package/dist/cjs/TimeSpan.js.map +1 -1
  9. package/dist/cjs/TimeStamp.js +1 -6
  10. package/dist/cjs/TimeStamp.js.map +1 -1
  11. package/dist/cjs/TimeUnit.js +11 -40
  12. package/dist/cjs/TimeUnit.js.map +1 -1
  13. package/dist/cjs/TimeUnitValue.js +0 -4
  14. package/dist/cjs/TimeUnitValue.js.map +1 -1
  15. package/dist/cjs/howMany.js +0 -46
  16. package/dist/cjs/howMany.js.map +1 -1
  17. package/dist/esm/ClockTime.js +19 -22
  18. package/dist/esm/ClockTime.js.map +1 -1
  19. package/dist/esm/DateTime.js +18 -102
  20. package/dist/esm/DateTime.js.map +1 -1
  21. package/dist/esm/TimeQuantity.js +19 -49
  22. package/dist/esm/TimeQuantity.js.map +1 -1
  23. package/dist/esm/TimeSpan.js +15 -56
  24. package/dist/esm/TimeSpan.js.map +1 -1
  25. package/dist/esm/TimeStamp.js +7 -10
  26. package/dist/esm/TimeStamp.js.map +1 -1
  27. package/dist/esm/TimeUnit.js +16 -43
  28. package/dist/esm/TimeUnit.js.map +1 -1
  29. package/dist/esm/TimeUnitValue.js +7 -8
  30. package/dist/esm/TimeUnitValue.js.map +1 -1
  31. package/dist/esm/date-time.js +10 -14
  32. package/dist/esm/date-time.js.map +1 -1
  33. package/dist/esm/howMany.js +1 -46
  34. package/dist/esm/howMany.js.map +1 -1
  35. package/dist/types/Calendars/Gregorian.d.ts +37 -0
  36. package/dist/types/DateTime.d.ts +60 -0
  37. package/dist/types/TimeQuantity.d.ts +19 -0
  38. package/dist/{TimeSpan.d.ts → types/TimeSpan.d.ts} +0 -40
  39. package/dist/{TimeStamp.d.ts → types/TimeStamp.d.ts} +0 -3
  40. package/dist/types/TimeUnit.d.ts +21 -0
  41. package/dist/{TimeUnitValue.d.ts → types/TimeUnitValue.d.ts} +0 -3
  42. package/dist/{howMany.d.ts → types/howMany.d.ts} +5 -5
  43. package/package.json +33 -43
  44. package/rollup.config.js +37 -0
  45. package/dist/Calendars/Gregorian.d.ts +0 -30
  46. package/dist/DateTime.d.ts +0 -154
  47. package/dist/TimeQuantity.d.ts +0 -50
  48. package/dist/TimeUnit.d.ts +0 -47
  49. package/dist/cjs/Calendars/Gregorian.js +0 -7
  50. package/dist/cjs/Calendars/Gregorian.js.map +0 -1
  51. package/dist/esm/Calendars/Gregorian.js +0 -6
  52. package/dist/esm/Calendars/Gregorian.js.map +0 -1
  53. package/dist/esm/DateTimeKind.js +0 -6
  54. package/dist/esm/DateTimeKind.js.map +0 -1
  55. package/dist/umd/Calendars/Gregorian.js +0 -17
  56. package/dist/umd/Calendars/Gregorian.js.map +0 -1
  57. package/dist/umd/ClockTime.js +0 -86
  58. package/dist/umd/ClockTime.js.map +0 -1
  59. package/dist/umd/DateTime.js +0 -320
  60. package/dist/umd/DateTime.js.map +0 -1
  61. package/dist/umd/DateTimeKind.js +0 -17
  62. package/dist/umd/DateTimeKind.js.map +0 -1
  63. package/dist/umd/TimeQuantity.js +0 -108
  64. package/dist/umd/TimeQuantity.js.map +0 -1
  65. package/dist/umd/TimeSpan.js +0 -148
  66. package/dist/umd/TimeSpan.js.map +0 -1
  67. package/dist/umd/TimeStamp.js +0 -65
  68. package/dist/umd/TimeStamp.js.map +0 -1
  69. package/dist/umd/TimeUnit.js +0 -111
  70. package/dist/umd/TimeUnit.js.map +0 -1
  71. package/dist/umd/TimeUnitValue.js +0 -58
  72. package/dist/umd/TimeUnitValue.js.map +0 -1
  73. package/dist/umd/date-time.js +0 -35
  74. package/dist/umd/date-time.js.map +0 -1
  75. package/dist/umd/howMany.js +0 -63
  76. package/dist/umd/howMany.js.map +0 -1
  77. /package/dist/{CalendarDate.d.ts → types/CalendarDate.d.ts} +0 -0
  78. /package/dist/{ClockTime.d.ts → types/ClockTime.d.ts} +0 -0
  79. /package/dist/{ClockTimeValue.d.ts → types/ClockTimeValue.d.ts} +0 -0
  80. /package/dist/{DateTimeKind.d.ts → types/DateTimeKind.d.ts} +0 -0
  81. /package/dist/{JsDateConvertible.d.ts → types/JsDateConvertible.d.ts} +0 -0
  82. /package/dist/{TimeMeasurement.d.ts → types/TimeMeasurement.d.ts} +0 -0
  83. /package/dist/{TimeStampValue.d.ts → types/TimeStampValue.d.ts} +0 -0
  84. /package/dist/{date-time.d.ts → types/date-time.d.ts} +0 -0
@@ -0,0 +1,60 @@
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * Based on .NET DateTime's interface.
4
+ * @license MIT
5
+ */
6
+ import CalendarDate from './CalendarDate';
7
+ import Gregorian from './Calendars/Gregorian';
8
+ import ClockTime from './ClockTime';
9
+ import DateTimeKind from './DateTimeKind';
10
+ import type JsDateConvertible from './JsDateConvertible';
11
+ import TimeQuantity from './TimeQuantity';
12
+ import TimeSpan from './TimeSpan';
13
+ import TimeStamp from './TimeStamp';
14
+ export default class DateTime implements CalendarDate, JsDateConvertible {
15
+ private readonly _value;
16
+ private readonly _kind;
17
+ private _time;
18
+ constructor();
19
+ constructor(dateString: string, kind?: DateTimeKind);
20
+ constructor(milliseconds: number, kind?: DateTimeKind);
21
+ constructor(source: Date, kind?: DateTimeKind);
22
+ constructor(source: DateTime, kind?: DateTimeKind);
23
+ static get now(): DateTime;
24
+ static get today(): DateTime;
25
+ static get tomorrow(): DateTime;
26
+ get kind(): DateTimeKind;
27
+ get year(): number;
28
+ get month(): Gregorian.Month;
29
+ get calendarMonth(): number;
30
+ get calendar(): CalendarDate;
31
+ get day(): number;
32
+ get dayIndex(): number;
33
+ get dayOfWeek(): Gregorian.DayOfWeek;
34
+ get date(): DateTime;
35
+ get timeOfDay(): ClockTime;
36
+ static between(first: Date | DateTime, last: Date | DateTime): TimeSpan;
37
+ static isLeapYear(year: number): boolean;
38
+ static daysInMonth(year: number, month: Gregorian.Month): number;
39
+ static from(calendarDate: CalendarDate): DateTime;
40
+ static from(year: number, month: Gregorian.Month, day: number): DateTime;
41
+ static fromCalendarDate(calendarDate: CalendarDate): DateTime;
42
+ static fromCalendarDate(year: number, month: number, day: number): DateTime;
43
+ toJsDate(): Date;
44
+ addMilliseconds(ms: number): DateTime;
45
+ addSeconds(seconds: number): DateTime;
46
+ addMinutes(minutes: number): DateTime;
47
+ addHours(hours: number): DateTime;
48
+ addDays(days: number): DateTime;
49
+ addMonths(months: number): DateTime;
50
+ addYears(years: number): DateTime;
51
+ add(time: TimeQuantity): DateTime;
52
+ subtract(time: TimeQuantity): DateTime;
53
+ timePassedSince(previous: Date | DateTime): TimeSpan;
54
+ toTimeStamp(): TimeStamp;
55
+ toUniversalTime(): DateTime;
56
+ equals(other: Date): boolean;
57
+ equals(other: JsDateConvertible, strict?: boolean): boolean;
58
+ compareTo(other: Date | JsDateConvertible): number;
59
+ equivalent(other: Date | JsDateConvertible): boolean;
60
+ }
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * @license MIT
4
+ */
5
+ import { ResettableLazy } from '@tsdotnet/lazy';
6
+ import type TimeMeasurement from './TimeMeasurement';
7
+ import TimeUnit from './TimeUnit';
8
+ export default class TimeQuantity {
9
+ protected _quantity: number;
10
+ constructor(_quantity?: number);
11
+ static getTotalMillisecondsFrom(values: Partial<TimeMeasurement>): number;
12
+ get direction(): number;
13
+ protected _total: ResettableLazy<Readonly<TimeMeasurement>>;
14
+ get total(): Readonly<TimeMeasurement>;
15
+ getTotalMilliseconds(): number;
16
+ equals(other: TimeQuantity): boolean;
17
+ compareTo(other: TimeQuantity): number;
18
+ getTotal(units: TimeUnit.UnitType): number;
19
+ }
@@ -7,46 +7,17 @@ import ClockTime from './ClockTime';
7
7
  import TimeMeasurement from './TimeMeasurement';
8
8
  import TimeQuantity from './TimeQuantity';
9
9
  import TimeUnit from './TimeUnit';
10
- /**
11
- * TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
12
- */
13
10
  export declare class TimeSpan extends TimeQuantity implements TimeMeasurement {
14
- /**
15
- * The total number of ticks that represent this amount of time.
16
- */
17
11
  readonly ticks: number;
18
- /**
19
- * The total number of ticks that milliseconds this amount of time.
20
- */
21
12
  readonly milliseconds: number;
22
- /**
23
- * The total number of ticks that seconds this amount of time.
24
- */
25
13
  readonly seconds: number;
26
- /**
27
- * The total number of ticks that minutes this amount of time.
28
- */
29
14
  readonly minutes: number;
30
- /**
31
- * The total number of ticks that hours this amount of time.
32
- */
33
15
  readonly hours: number;
34
- /**
35
- * The total number of ticks that days this amount of time.
36
- */
37
16
  readonly days: number;
38
17
  protected constructor(value: number, units?: TimeUnit.UnitType);
39
18
  static get zero(): TimeSpan;
40
- /**
41
- * Provides an standard interface for acquiring the total time.
42
- * @returns {TimeSpan}
43
- */
44
19
  get total(): TimeSpan;
45
20
  private _time;
46
- /**
47
- * The value of this TimeSpan reduced to the clock and calendar.
48
- * @return {ClockTime}
49
- */
50
21
  get time(): ClockTime;
51
22
  static from(values: Partial<TimeMeasurement>): TimeSpan;
52
23
  static from(value: number, units: TimeUnit.UnitType): TimeSpan;
@@ -56,18 +27,7 @@ export declare class TimeSpan extends TimeQuantity implements TimeMeasurement {
56
27
  static fromSeconds(value: number): TimeSpan;
57
28
  static fromMilliseconds(value: number): TimeSpan;
58
29
  static fromTicks(value: number): TimeSpan;
59
- /**
60
- * Sum the value of this TimeSpan with another time quantity.
61
- * @param {TimeQuantity | Partial<TimeMeasurement>} other
62
- * @return {TimeSpan}
63
- */
64
30
  add(other: TimeSpan | TimeQuantity | Partial<TimeMeasurement>): TimeSpan;
65
- /**
66
- * Sum the value of this TimeSpan with another unit value.
67
- * @param {number} value
68
- * @param {TimeUnit.UnitType} units
69
- * @return {TimeSpan}
70
- */
71
31
  addUnit(value: number, units?: TimeUnit.UnitType): TimeSpan;
72
32
  }
73
33
  export default TimeSpan;
@@ -5,9 +5,6 @@
5
5
  import Gregorian from './Calendars/Gregorian';
6
6
  import JsDateConvertible from './JsDateConvertible';
7
7
  import TimeStampValue from './TimeStampValue';
8
- /**
9
- * An alternative to Date or DateTime. Is a model representing the exact date and time.
10
- */
11
8
  export declare class TimeStamp implements Required<TimeStampValue>, JsDateConvertible {
12
9
  readonly year: number;
13
10
  readonly month: Gregorian.Month;
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * Originally based upon .NET source but with many additions and improvements.
4
+ * @license MIT
5
+ */
6
+ import TimeQuantity from './TimeQuantity';
7
+ export declare namespace TimeUnit {
8
+ enum UnitType {
9
+ Ticks = 0,
10
+ Milliseconds = 1,
11
+ Seconds = 2,
12
+ Minutes = 3,
13
+ Hours = 4,
14
+ Days = 5
15
+ }
16
+ function toMilliseconds(value: number, units: UnitType): number;
17
+ function fromMilliseconds(ms: number, units: UnitType): number;
18
+ function from(quantity: TimeQuantity, toUnits: UnitType): number;
19
+ function assertValid(unit: UnitType): true | never;
20
+ }
21
+ export default TimeUnit;
@@ -4,9 +4,6 @@
4
4
  */
5
5
  import TimeQuantity from './TimeQuantity';
6
6
  import TimeUnit from './TimeUnit';
7
- /**
8
- * TimeUnitValue allows for passing around a reference to a mutable measure of time coerced by its unit type.
9
- */
10
7
  export default class TimeUnitValue extends TimeQuantity {
11
8
  private _units;
12
9
  constructor(value: number | TimeQuantity, _units: TimeUnit.UnitType);
@@ -3,25 +3,25 @@
3
3
  * @license MIT
4
4
  */
5
5
  export declare namespace hours {
6
- enum per {
6
+ const enum per {
7
7
  day = 24
8
8
  }
9
9
  }
10
10
  export declare namespace minutes {
11
- enum per {
11
+ const enum per {
12
12
  hour = 60,
13
13
  day = 1440
14
14
  }
15
15
  }
16
16
  export declare namespace seconds {
17
- enum per {
17
+ const enum per {
18
18
  minute = 60,
19
19
  hour = 3600,
20
20
  day = 86400
21
21
  }
22
22
  }
23
23
  export declare namespace milliseconds {
24
- enum per {
24
+ const enum per {
25
25
  second = 1000,
26
26
  minute = 60000,
27
27
  hour = 3600000,
@@ -29,7 +29,7 @@ export declare namespace milliseconds {
29
29
  }
30
30
  }
31
31
  export declare namespace ticks {
32
- enum per {
32
+ const enum per {
33
33
  millisecond = 10000,
34
34
  second = 10000000,
35
35
  minute = 600000000,
package/package.json CHANGED
@@ -1,44 +1,41 @@
1
1
  {
2
2
  "name": "@tsdotnet/date-time",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "author": "electricessence",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "exports": {
8
9
  ".": {
10
+ "types": "./dist/types/date-time.d.ts",
9
11
  "import": "./dist/esm/date-time.js",
10
- "require": "./dist/cjs/date-time.js",
11
- "types": "./dist/date-time.d.ts"
12
- },
13
- "./howMany": {
14
- "import": "./dist/esm/howMany.js",
15
- "require": "./dist/cjs/howMany.js",
16
- "types": "./dist/howMany.d.ts"
12
+ "require": "./dist/cjs/date-time.js"
17
13
  }
18
14
  },
19
- "types": "dist/date-time.d.ts",
20
- "main": "dist/cjs/date-time.js",
21
- "module": "dist/esm/date-time.js",
22
- "umd:main": "dist/umd/date-time.js",
23
- "unpkg": "dist/umd/date-time.js",
24
- "jsdelivr": "dist/umd/date-time.js",
25
- "keywords": [],
15
+ "types": "./dist/types/date-time.d.ts",
16
+ "keywords": [
17
+ "dispose",
18
+ "disposal",
19
+ "disposable",
20
+ "IDisposable",
21
+ "DisposableBase",
22
+ "ObjectDisposedException"
23
+ ],
26
24
  "scripts": {
27
25
  "clean": "rimraf dist",
26
+ "build:types": "cpy \"src/**/*.d.ts\" dist/types --parents && tsc -p tsconfig.types.json",
27
+ "build:esm": "rollup -c rollup.config.js",
28
28
  "build:cjs": "tsc -p tsconfig.cjs.json",
29
- "build:esm": "tsc -p tsconfig.esm.json",
30
- "build:umd": "tsc -p tsconfig.umd.json",
31
- "build:types": "cpy \"src/**/*.d.ts\" dist --parents && tsc -p tsconfig.types.json",
32
- "build": "pnpm i && pnpm run clean && concurrently \"pnpm:build:*\"",
33
- "bump": "pnpm run precommit && pnpm version patch",
34
- "docs": "rimraf docs && typedoc --options typedoc.json --readme none",
29
+ "build": "pnpm clean && pnpm build:types && pnpm build:esm && pnpm build:cjs",
30
+ "test": "vitest run",
31
+ "typecheck": "tsc --noEmit",
35
32
  "lint": "eslint src/**/*.ts",
36
- "precommit": "pnpm i && pnpm run build && pnpm run lint && pnpm run validate && pnpm run test && git status -s",
37
- "prepublishOnly": "pnpm run build && pnpm run validate && pnpm run test",
38
- "preversion": "pnpm run lint && pnpm run test",
33
+ "docs": "rimraf docs && typedoc --options typedoc.json --readme none",
34
+ "bump": "pnpm run precommit && pnpm version patch",
35
+ "precommit": "pnpm build && pnpm test && pnpm lint && git status -s",
36
+ "preversion": "pnpm lint && pnpm test",
39
37
  "postversion": "git push && git push --tags && pnpm run docs && git add -A && git commit -m \"Updated docs.\" docs && git push",
40
- "test": "tsx node_modules/mocha/bin/_mocha tests/**/*.ts",
41
- "validate": "node ./.build/validate-package.js"
38
+ "prepublishOnly": "pnpm build && pnpm test && pnpm lint"
42
39
  },
43
40
  "repository": {
44
41
  "type": "git",
@@ -50,26 +47,23 @@
50
47
  "homepage": "https://github.com/tsdotnet/date-time#readme",
51
48
  "devDependencies": {
52
49
  "@eslint/js": "^9.33.0",
53
- "@tsdotnet/random": "^1.1.1",
54
- "@types/chai": "^5.2.2",
55
- "@types/mocha": "^10.0.10",
50
+ "@rollup/plugin-node-resolve": "^16.0.1",
51
+ "@rollup/plugin-typescript": "^12.1.4",
56
52
  "@types/node": "^24.3.0",
57
- "chai": "^5.2.1",
58
- "concurrently": "^9.2.0",
59
53
  "cpy-cli": "^6.0.0",
60
54
  "eslint": "^9.33.0",
61
- "mocha": "^11.7.1",
62
55
  "rimraf": "^6.0.1",
63
- "tsx": "^4.20.4",
56
+ "rollup": "^4.46.3",
64
57
  "typedoc": "^0.28.10",
65
58
  "typescript": "^5.9.2",
66
- "typescript-eslint": "^8.39.1"
59
+ "typescript-eslint": "^8.40.0",
60
+ "vitest": "^3.2.4"
67
61
  },
68
62
  "dependencies": {
69
- "@tsdotnet/compare": "^1.5.1",
70
- "@tsdotnet/exceptions": "^1.2.2",
71
- "@tsdotnet/lazy": "^1.1.0",
72
- "@tsdotnet/type": "^1.2.1",
63
+ "@tsdotnet/compare": "^1.5.4",
64
+ "@tsdotnet/exceptions": "^1.2.4",
65
+ "@tsdotnet/lazy": "^1.1.2",
66
+ "@tsdotnet/type": "^1.2.4",
73
67
  "tslib": "^2.8.1"
74
68
  },
75
69
  "pnpm": {
@@ -82,16 +76,12 @@
82
76
  "json5@<1.0.2": ">=1.0.2",
83
77
  "json5@>=2.0.0 <2.2.2": ">=2.2.2",
84
78
  "minimatch@<3.0.5": ">=3.0.5",
85
- "word-wrap@<1.2.4": ">=1.2.4",
86
79
  "semver@<5.7.2": ">=5.7.2",
87
80
  "semver@>=6.0.0 <6.3.1": ">=6.3.1",
88
81
  "semver@>=7.0.0 <7.5.2": ">=7.5.2",
89
82
  "get-func-name@<2.0.1": ">=2.0.1",
90
83
  "@babel/traverse@<7.23.2": ">=7.23.2",
91
84
  "braces@<3.0.3": ">=3.0.3"
92
- },
93
- "ignoredBuiltDependencies": [
94
- "esbuild"
95
- ]
85
+ }
96
86
  }
97
87
  }
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from 'rollup';
2
+ import typescript from '@rollup/plugin-typescript';
3
+ import { readFileSync } from 'node:fs';
4
+
5
+ const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)));
6
+
7
+ export default defineConfig({
8
+ input: 'src/date-time.ts', // Just use the main entry point
9
+ output: {
10
+ dir: 'dist/esm',
11
+ format: 'es',
12
+ preserveModules: true, // This will automatically include all imported files!
13
+ preserveModulesRoot: 'src',
14
+ entryFileNames: '[name].js',
15
+ sourcemap: true
16
+ },
17
+ external: [
18
+ // Node core modules
19
+ /^node:/,
20
+ // All dependencies and peer dependencies
21
+ ...Object.keys(pkg.dependencies || {}),
22
+ ...Object.keys(pkg.peerDependencies || {})
23
+ ],
24
+ plugins: [
25
+ typescript({
26
+ tsconfig: './tsconfig.esm.json',
27
+ declaration: false, // Keep your existing types build
28
+ declarationMap: false,
29
+ sourceMap: true,
30
+ removeComments: true // Explicitly remove source comments
31
+ })
32
+ ]
33
+ });
34
+
35
+
36
+
37
+
@@ -1,30 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- declare namespace Gregorian {
6
- const enum Month {
7
- January = 0,
8
- February = 1,
9
- March = 2,
10
- April = 3,
11
- May = 4,
12
- June = 5,
13
- July = 6,
14
- August = 7,
15
- September = 8,
16
- October = 9,
17
- November = 10,
18
- December = 11
19
- }
20
- const enum DayOfWeek {
21
- Sunday = 0,
22
- Monday = 1,
23
- Tuesday = 2,
24
- Wednesday = 3,
25
- Thursday = 4,
26
- Friday = 5,
27
- Saturday = 6
28
- }
29
- }
30
- export default Gregorian;
@@ -1,154 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * Based on .NET DateTime's interface.
4
- * @license MIT
5
- */
6
- import CalendarDate from './CalendarDate';
7
- import Gregorian from './Calendars/Gregorian';
8
- import ClockTime from './ClockTime';
9
- import DateTimeKind from './DateTimeKind';
10
- import type JsDateConvertible from './JsDateConvertible';
11
- import TimeQuantity from './TimeQuantity';
12
- import TimeSpan from './TimeSpan';
13
- import TimeStamp from './TimeStamp';
14
- export default class DateTime implements CalendarDate, JsDateConvertible {
15
- private readonly _value;
16
- private readonly _kind;
17
- private _time;
18
- constructor();
19
- constructor(dateString: string, kind?: DateTimeKind);
20
- constructor(milliseconds: number, kind?: DateTimeKind);
21
- constructor(source: Date, kind?: DateTimeKind);
22
- constructor(source: DateTime, kind?: DateTimeKind);
23
- /**
24
- * Returns the now local time.
25
- * @returns {DateTime}
26
- */
27
- static get now(): DateTime;
28
- /**
29
- * The date component for now.
30
- * @returns {DateTime}
31
- */
32
- static get today(): DateTime;
33
- /**
34
- * Midnight tomorrow.
35
- * @returns {DateTime}
36
- */
37
- static get tomorrow(): DateTime;
38
- get kind(): DateTimeKind;
39
- get year(): number;
40
- /**
41
- * Returns the Gregorian Month (zero indexed).
42
- * @returns {number}
43
- */
44
- get month(): Gregorian.Month;
45
- /**
46
- * Returns the month number (1-12).
47
- * @returns {number}
48
- */
49
- get calendarMonth(): number;
50
- get calendar(): CalendarDate;
51
- /**
52
- * Returns the day of the month. An integer between 1 and 31.
53
- * @returns {number}
54
- */
55
- get day(): number;
56
- /**
57
- * Returns the day of the month indexed starting at zero.
58
- * @returns {number}
59
- */
60
- get dayIndex(): number;
61
- /**
62
- * Returns the zero indexed day of the week. (Sunday == 0)
63
- * @returns {number}
64
- */
65
- get dayOfWeek(): Gregorian.DayOfWeek;
66
- /**
67
- * Returns a DateTime object for 00:00 of this date.
68
- */
69
- get date(): DateTime;
70
- /**
71
- * Returns the time of day represented by a ClockTime object.
72
- * @returns {ClockTime}
73
- */
74
- get timeOfDay(): ClockTime;
75
- /**
76
- * Measures the difference between two dates as a TimeSpan.
77
- * @param first
78
- * @param last
79
- */
80
- static between(first: Date | DateTime, last: Date | DateTime): TimeSpan;
81
- /**
82
- * Calculates if the given year is a leap year using the formula:
83
- * ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)
84
- * @param year
85
- * @returns {boolean}
86
- */
87
- static isLeapYear(year: number): boolean;
88
- /**
89
- * Returns the number of days for the specific year and month.
90
- * @param year
91
- * @param month
92
- * @returns {any}
93
- */
94
- static daysInMonth(year: number, month: Gregorian.Month): number;
95
- static from(calendarDate: CalendarDate): DateTime;
96
- static from(year: number, month: Gregorian.Month, day: number): DateTime;
97
- static fromCalendarDate(calendarDate: CalendarDate): DateTime;
98
- static fromCalendarDate(year: number, month: number, day: number): DateTime;
99
- toJsDate(): Date;
100
- addMilliseconds(ms: number): DateTime;
101
- addSeconds(seconds: number): DateTime;
102
- addMinutes(minutes: number): DateTime;
103
- addHours(hours: number): DateTime;
104
- addDays(days: number): DateTime;
105
- addMonths(months: number): DateTime;
106
- addYears(years: number): DateTime;
107
- /**
108
- * Receives an TimeQuantity value and adds based on the total milliseconds.
109
- * @param {TimeQuantity} time
110
- * @returns {DateTime}
111
- */
112
- add(time: TimeQuantity): DateTime;
113
- /**
114
- * Receives an TimeQuantity value and subtracts based on the total milliseconds.
115
- * @param {TimeQuantity} time
116
- * @returns {DateTime}
117
- */
118
- subtract(time: TimeQuantity): DateTime;
119
- /**
120
- * Returns a TimeSpan representing the amount of time between two dates.
121
- * @param previous
122
- * @returns {TimeSpan}
123
- */
124
- timePassedSince(previous: Date | DateTime): TimeSpan;
125
- /**
126
- * Returns a readonly object which contains all the date and time components.
127
- */
128
- toTimeStamp(): TimeStamp;
129
- /**
130
- * Returns a UTC version of this date if its kind is local.
131
- * @returns {DateTime}
132
- */
133
- toUniversalTime(): DateTime;
134
- /**
135
- * Compares a JS Date with the current instance. Does not evaluate the kind.
136
- * @param other
137
- * @returns {boolean}
138
- */
139
- equals(other: Date): boolean;
140
- /**
141
- * Compares another JsDateConvertible object and returns true if they or their value are equal.
142
- * @param other The other JsDateConvertible object.
143
- * @param strict When strict is true, the 'kind' also must match.
144
- * @returns {boolean}
145
- */
146
- equals(other: JsDateConvertible, strict?: boolean): boolean;
147
- compareTo(other: Date | JsDateConvertible): number;
148
- /**
149
- * Returns true if the value is the same UTC time.
150
- * @param {Date | JsDateConvertible} other
151
- * @return {boolean}
152
- */
153
- equivalent(other: Date | JsDateConvertible): boolean;
154
- }
@@ -1,50 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- import { ResettableLazy } from '@tsdotnet/lazy';
6
- import type TimeMeasurement from './TimeMeasurement';
7
- import TimeUnit from './TimeUnit';
8
- /**
9
- * This class provides a simple means for storing and calculating time quantities.
10
- */
11
- export default class TimeQuantity {
12
- protected _quantity: number;
13
- constructor(_quantity?: number);
14
- /**
15
- * Combine total values by time unit.
16
- * @param {Partial<TimeMeasurement>} values
17
- * @return {number}
18
- */
19
- static getTotalMillisecondsFrom(values: Partial<TimeMeasurement>): number;
20
- /**
21
- * +1, 0, or -1 depending on the time direction.
22
- * @returns {number}
23
- */
24
- get direction(): number;
25
- protected _total: ResettableLazy<Readonly<TimeMeasurement>>;
26
- /**
27
- * Returns an object with all units exposed as totals.
28
- * @returns {TimeMeasurement}
29
- */
30
- get total(): Readonly<TimeMeasurement>;
31
- getTotalMilliseconds(): number;
32
- /**
33
- * Compares this instance against any other time quantity instance and return true if the amount of time is the same.
34
- * @param other
35
- * @returns {boolean}
36
- */
37
- equals(other: TimeQuantity): boolean;
38
- /**
39
- * Compares this instance against any other time quantity instance.
40
- * @param other
41
- * @returns {number}
42
- */
43
- compareTo(other: TimeQuantity): number;
44
- /**
45
- * Returns the total amount of time measured in the requested TimeUnit.
46
- * @param units
47
- * @returns {number}
48
- */
49
- getTotal(units: TimeUnit.UnitType): number;
50
- }
@@ -1,47 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * Originally based upon .NET source but with many additions and improvements.
4
- * @license MIT
5
- */
6
- import TimeQuantity from './TimeQuantity';
7
- export declare namespace TimeUnit {
8
- /**
9
- * A distinct unit of time measurement.
10
- */
11
- enum UnitType {
12
- Ticks = 0,
13
- Milliseconds = 1,
14
- Seconds = 2,
15
- Minutes = 3,
16
- Hours = 4,
17
- Days = 5
18
- }
19
- /**
20
- * Converts any TimeUnit value to it's respective millisecond quantity.
21
- * @param {number} value
22
- * @param {UnitType} units
23
- * @return {number} Number of milliseconds representing the specified units.
24
- */
25
- function toMilliseconds(value: number, units: UnitType): number;
26
- /**
27
- * Converts milliseconds to the specified TimeUnit quantity.
28
- * @param {number} ms
29
- * @param {UnitType} units
30
- * @return {number}
31
- */
32
- function fromMilliseconds(ms: number, units: UnitType): number;
33
- /**
34
- * Converts a TimeQuantity to the the TimeUnit requested..
35
- * @param {TimeQuantity} quantity
36
- * @param {UnitType} toUnits
37
- * @return {number}
38
- */
39
- function from(quantity: TimeQuantity, toUnits: UnitType): number;
40
- /**
41
- * Asserts if the time unit value is valid.
42
- * @param {UnitType} unit
43
- * @return {true}
44
- */
45
- function assertValid(unit: UnitType): true | never;
46
- }
47
- export default TimeUnit;