@bodil/core 0.1.2 → 0.1.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/dist/date.d.ts CHANGED
@@ -85,3 +85,28 @@ export declare function secondsBetween(a: Date, b: Date): number;
85
85
  * Calculate the number of milliseconds between two {@link Date}s.
86
86
  */
87
87
  export declare function millisBetween(a: Date, b: Date): Milliseconds;
88
+ /**
89
+ * Test if a {@link Date} is more than the given number of milliseconds before
90
+ * the present.
91
+ */
92
+ export declare function isOlderThan(date: Date, millis: Milliseconds): boolean;
93
+ /**
94
+ * Test if a {@link Date} is more than the given number of seconds before the
95
+ * present.
96
+ */
97
+ export declare function isOlderThanSeconds(date: Date, seconds: number): boolean;
98
+ /**
99
+ * Test if a {@link Date} is more than the given number of minutes before the
100
+ * present.
101
+ */
102
+ export declare function isOlderThanMinutes(date: Date, minutes: number): boolean;
103
+ /**
104
+ * Test if a {@link Date} is more than the given number of hours before the
105
+ * present.
106
+ */
107
+ export declare function isOlderThanHours(date: Date, hours: number): boolean;
108
+ /**
109
+ * Test if a {@link Date} is more than the given number of days before the
110
+ * present.
111
+ */
112
+ export declare function isOlderThanDays(date: Date, days: number): boolean;
package/dist/date.js CHANGED
@@ -123,4 +123,39 @@ export function secondsBetween(a, b) {
123
123
  export function millisBetween(a, b) {
124
124
  return +a - +b;
125
125
  }
126
+ /**
127
+ * Test if a {@link Date} is more than the given number of milliseconds before
128
+ * the present.
129
+ */
130
+ export function isOlderThan(date, millis) {
131
+ return date <= subMillis(new Date(), millis);
132
+ }
133
+ /**
134
+ * Test if a {@link Date} is more than the given number of seconds before the
135
+ * present.
136
+ */
137
+ export function isOlderThanSeconds(date, seconds) {
138
+ return date <= subMillis(new Date(), seconds * MILLIS_IN_SECOND);
139
+ }
140
+ /**
141
+ * Test if a {@link Date} is more than the given number of minutes before the
142
+ * present.
143
+ */
144
+ export function isOlderThanMinutes(date, minutes) {
145
+ return date <= subMillis(new Date(), minutes * MILLIS_IN_MINUTE);
146
+ }
147
+ /**
148
+ * Test if a {@link Date} is more than the given number of hours before the
149
+ * present.
150
+ */
151
+ export function isOlderThanHours(date, hours) {
152
+ return date <= subMillis(new Date(), hours * MILLIS_IN_HOUR);
153
+ }
154
+ /**
155
+ * Test if a {@link Date} is more than the given number of days before the
156
+ * present.
157
+ */
158
+ export function isOlderThanDays(date, days) {
159
+ return date <= subMillis(new Date(), days * MILLIS_IN_DAY);
160
+ }
126
161
  //# sourceMappingURL=date.js.map
package/dist/date.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,QAAwB,CAAC;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAuB,CAAC;AACtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAqB,CAAC;AACtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAoB,CAAC;AAIrD;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,GAAG,KAAkB;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,GAAG,KAAkB;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,CAAO,EAAE,CAAO;IACvC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/C,CAAC;AA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CAAC,IAAI,IAAI,EAAE,EAAE,KAAK,GAAG,cAAc,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAU,EAAE,IAAY;IACpD,OAAO,IAAI,IAAI,SAAS,CAAC,IAAI,IAAI,EAAE,EAAE,IAAI,GAAG,aAAa,CAAC,CAAC;AAC/D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bodil/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "My TypeScript standard library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -71,16 +71,16 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@bodil/opt-vitest": "^1.0.0",
74
- "@eslint/eslintrc": "^3.2.0",
75
- "@eslint/js": "^9.18.0",
76
- "@typescript-eslint/eslint-plugin": "^8.21.0",
77
- "@typescript-eslint/parser": "^8.21.0",
78
- "eslint": "^9.18.0",
79
- "eslint-config-prettier": "^10.0.1",
80
- "eslint-plugin-jsdoc": "^50.6.2",
81
- "globals": "^15.14.0",
82
- "typescript": "^5.7.3",
83
- "vitest": "^3.0.2"
74
+ "@eslint/eslintrc": "^3.3.1",
75
+ "@eslint/js": "^9.28.0",
76
+ "@typescript-eslint/eslint-plugin": "^8.33.1",
77
+ "@typescript-eslint/parser": "^8.33.1",
78
+ "eslint": "^9.28.0",
79
+ "eslint-config-prettier": "^10.1.5",
80
+ "eslint-plugin-jsdoc": "^50.7.1",
81
+ "globals": "^15.15.0",
82
+ "typescript": "^5.8.3",
83
+ "vitest": "^3.2.2"
84
84
  },
85
85
  "scripts": {
86
86
  "build": "tsc",
package/src/date.ts CHANGED
@@ -143,3 +143,43 @@ export function secondsBetween(a: Date, b: Date): number {
143
143
  export function millisBetween(a: Date, b: Date): Milliseconds {
144
144
  return +a - +b;
145
145
  }
146
+
147
+ /**
148
+ * Test if a {@link Date} is more than the given number of milliseconds before
149
+ * the present.
150
+ */
151
+ export function isOlderThan(date: Date, millis: Milliseconds): boolean {
152
+ return date <= subMillis(new Date(), millis);
153
+ }
154
+
155
+ /**
156
+ * Test if a {@link Date} is more than the given number of seconds before the
157
+ * present.
158
+ */
159
+ export function isOlderThanSeconds(date: Date, seconds: number): boolean {
160
+ return date <= subMillis(new Date(), seconds * MILLIS_IN_SECOND);
161
+ }
162
+
163
+ /**
164
+ * Test if a {@link Date} is more than the given number of minutes before the
165
+ * present.
166
+ */
167
+ export function isOlderThanMinutes(date: Date, minutes: number): boolean {
168
+ return date <= subMillis(new Date(), minutes * MILLIS_IN_MINUTE);
169
+ }
170
+
171
+ /**
172
+ * Test if a {@link Date} is more than the given number of hours before the
173
+ * present.
174
+ */
175
+ export function isOlderThanHours(date: Date, hours: number): boolean {
176
+ return date <= subMillis(new Date(), hours * MILLIS_IN_HOUR);
177
+ }
178
+
179
+ /**
180
+ * Test if a {@link Date} is more than the given number of days before the
181
+ * present.
182
+ */
183
+ export function isOlderThanDays(date: Date, days: number): boolean {
184
+ return date <= subMillis(new Date(), days * MILLIS_IN_DAY);
185
+ }