@naturalcycles/js-lib 14.91.0 → 14.91.1

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.
@@ -1,5 +1,6 @@
1
1
  import { Sequence } from '../seq/seq';
2
2
  import { IsoDate } from '../types';
3
+ import { LocalTime } from './localTime';
3
4
  export declare type LocalDateUnit = 'year' | 'month' | 'day';
4
5
  export declare type LocalDateConfig = LocalDate | string;
5
6
  /**
@@ -70,6 +71,7 @@ export declare class LocalDate {
70
71
  * Timezone will match local timezone.
71
72
  */
72
73
  toDate(): Date;
74
+ toLocalTime(): LocalTime;
73
75
  toString(): IsoDate;
74
76
  toStringCompact(): string;
75
77
  toJSON(): IsoDate;
@@ -4,6 +4,7 @@ exports.localDate = exports.LocalDate = void 0;
4
4
  const assert_1 = require("../error/assert");
5
5
  const seq_1 = require("../seq/seq");
6
6
  const types_1 = require("../types");
7
+ const localTime_1 = require("./localTime");
7
8
  const m31 = new Set([1, 3, 5, 7, 8, 10, 12]);
8
9
  /**
9
10
  * @experimental
@@ -282,6 +283,9 @@ class LocalDate {
282
283
  toDate() {
283
284
  return new Date(this.year, this.month - 1, this.day);
284
285
  }
286
+ toLocalTime() {
287
+ return localTime_1.LocalTime.of(this.toDate());
288
+ }
285
289
  toString() {
286
290
  return [
287
291
  String(this.year).padStart(4, '0'),
@@ -1,4 +1,5 @@
1
- import { IsoDateTime, UnixTimestamp } from '../types';
1
+ import { IsoDate, IsoDateTime, UnixTimestamp } from '../types';
2
+ import { LocalDate } from './localDate';
2
3
  export declare type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
3
4
  export declare type LocalTimeConfig = LocalTime | Date | IsoDateTime | UnixTimestamp;
4
5
  export interface LocalTimeComponents {
@@ -72,8 +73,16 @@ export declare class LocalTime {
72
73
  clone(): LocalTime;
73
74
  unix(): UnixTimestamp;
74
75
  valueOf(): UnixTimestamp;
75
- toISO8601(): IsoDateTime;
76
+ toLocalDate(): LocalDate;
76
77
  toPretty(seconds?: boolean): IsoDateTime;
78
+ /**
79
+ * Returns e.g: `1984-06-21T17:56:21`, only the date part of DateTime
80
+ */
81
+ toISODateTime(): IsoDateTime;
82
+ /**
83
+ * Returns e.g: `1984-06-21`, only the date part of DateTime
84
+ */
85
+ toISODate(): IsoDate;
77
86
  /**
78
87
  * Returns e.g: `19840621_1705`
79
88
  */
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.localTime = exports.LocalTime = void 0;
4
4
  const assert_1 = require("../error/assert");
5
+ const localDate_1 = require("./localDate");
5
6
  /* eslint-disable no-dupe-class-members */
6
7
  // Design choices:
7
8
  // No milliseconds
@@ -297,8 +298,8 @@ class LocalTime {
297
298
  valueOf() {
298
299
  return Math.floor(this.$date.valueOf() / 1000);
299
300
  }
300
- toISO8601() {
301
- return this.$date.toISOString().slice(0, 19);
301
+ toLocalDate() {
302
+ return localDate_1.LocalDate.create(this.$date.getFullYear(), this.$date.getMonth() + 1, this.$date.getDate());
302
303
  }
303
304
  toPretty(seconds = true) {
304
305
  return this.$date
@@ -307,6 +308,18 @@ class LocalTime {
307
308
  .split('T')
308
309
  .join(' ');
309
310
  }
311
+ /**
312
+ * Returns e.g: `1984-06-21T17:56:21`, only the date part of DateTime
313
+ */
314
+ toISODateTime() {
315
+ return this.$date.toISOString().slice(0, 19);
316
+ }
317
+ /**
318
+ * Returns e.g: `1984-06-21`, only the date part of DateTime
319
+ */
320
+ toISODate() {
321
+ return this.$date.toISOString().slice(0, 10);
322
+ }
310
323
  /**
311
324
  * Returns e.g: `19840621_1705`
312
325
  */
@@ -1,6 +1,7 @@
1
1
  import { _assert } from '../error/assert';
2
2
  import { Sequence } from '../seq/seq';
3
3
  import { END } from '../types';
4
+ import { LocalTime } from './localTime';
4
5
  const m31 = new Set([1, 3, 5, 7, 8, 10, 12]);
5
6
  /**
6
7
  * @experimental
@@ -279,6 +280,9 @@ export class LocalDate {
279
280
  toDate() {
280
281
  return new Date(this.year, this.month - 1, this.day);
281
282
  }
283
+ toLocalTime() {
284
+ return LocalTime.of(this.toDate());
285
+ }
282
286
  toString() {
283
287
  return [
284
288
  String(this.year).padStart(4, '0'),
@@ -1,4 +1,5 @@
1
1
  import { _assert } from '../error/assert';
2
+ import { LocalDate } from './localDate';
2
3
  /* eslint-disable no-dupe-class-members */
3
4
  // Design choices:
4
5
  // No milliseconds
@@ -294,8 +295,8 @@ export class LocalTime {
294
295
  valueOf() {
295
296
  return Math.floor(this.$date.valueOf() / 1000);
296
297
  }
297
- toISO8601() {
298
- return this.$date.toISOString().slice(0, 19);
298
+ toLocalDate() {
299
+ return LocalDate.create(this.$date.getFullYear(), this.$date.getMonth() + 1, this.$date.getDate());
299
300
  }
300
301
  toPretty(seconds = true) {
301
302
  return this.$date
@@ -304,6 +305,18 @@ export class LocalTime {
304
305
  .split('T')
305
306
  .join(' ');
306
307
  }
308
+ /**
309
+ * Returns e.g: `1984-06-21T17:56:21`, only the date part of DateTime
310
+ */
311
+ toISODateTime() {
312
+ return this.$date.toISOString().slice(0, 19);
313
+ }
314
+ /**
315
+ * Returns e.g: `1984-06-21`, only the date part of DateTime
316
+ */
317
+ toISODate() {
318
+ return this.$date.toISOString().slice(0, 10);
319
+ }
307
320
  /**
308
321
  * Returns e.g: `19840621_1705`
309
322
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.91.0",
3
+ "version": "14.91.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -1,6 +1,7 @@
1
1
  import { _assert } from '../error/assert'
2
2
  import { Sequence } from '../seq/seq'
3
3
  import { END, IsoDate } from '../types'
4
+ import { LocalTime } from './localTime'
4
5
 
5
6
  export type LocalDateUnit = 'year' | 'month' | 'day'
6
7
 
@@ -356,6 +357,10 @@ export class LocalDate {
356
357
  return new Date(this.year, this.month - 1, this.day)
357
358
  }
358
359
 
360
+ toLocalTime(): LocalTime {
361
+ return LocalTime.of(this.toDate())
362
+ }
363
+
359
364
  toString(): IsoDate {
360
365
  return [
361
366
  String(this.year).padStart(4, '0'),
@@ -1,5 +1,6 @@
1
1
  import { _assert } from '../error/assert'
2
- import { IsoDateTime, UnixTimestamp } from '../types'
2
+ import { IsoDate, IsoDateTime, UnixTimestamp } from '../types'
3
+ import { LocalDate } from './localDate'
3
4
 
4
5
  export type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
5
6
 
@@ -355,8 +356,12 @@ export class LocalTime {
355
356
  return Math.floor(this.$date.valueOf() / 1000)
356
357
  }
357
358
 
358
- toISO8601(): IsoDateTime {
359
- return this.$date.toISOString().slice(0, 19)
359
+ toLocalDate(): LocalDate {
360
+ return LocalDate.create(
361
+ this.$date.getFullYear(),
362
+ this.$date.getMonth() + 1,
363
+ this.$date.getDate(),
364
+ )
360
365
  }
361
366
 
362
367
  toPretty(seconds = true): IsoDateTime {
@@ -367,6 +372,20 @@ export class LocalTime {
367
372
  .join(' ')
368
373
  }
369
374
 
375
+ /**
376
+ * Returns e.g: `1984-06-21T17:56:21`, only the date part of DateTime
377
+ */
378
+ toISODateTime(): IsoDateTime {
379
+ return this.$date.toISOString().slice(0, 19)
380
+ }
381
+
382
+ /**
383
+ * Returns e.g: `1984-06-21`, only the date part of DateTime
384
+ */
385
+ toISODate(): IsoDate {
386
+ return this.$date.toISOString().slice(0, 10)
387
+ }
388
+
370
389
  /**
371
390
  * Returns e.g: `19840621_1705`
372
391
  */