qrono 1.2.0 → 1.3.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/src/qrono.js CHANGED
@@ -33,16 +33,6 @@ const defaultContext = {
33
33
  disambiguation: 'compatible',
34
34
  }
35
35
 
36
- for (const key of fields(defaultContext)) {
37
- Qrono[key] = function (arg) {
38
- if (given(arg)) {
39
- defaultContext[key] = arg
40
- return this
41
- }
42
- return defaultContext[key]
43
- }
44
- }
45
-
46
36
  Qrono.context = function (context) {
47
37
  if (given(context)) {
48
38
  for (const key of fields(defaultContext)) {
@@ -56,16 +46,6 @@ Qrono.context = function (context) {
56
46
  return { ...defaultContext }
57
47
  }
58
48
 
59
- Qrono.asUtc = function () {
60
- defaultContext.localtime = false
61
- return this
62
- }
63
-
64
- Qrono.asLocaltime = function () {
65
- defaultContext.localtime = true
66
- return this
67
- }
68
-
69
49
  const monday = 1
70
50
  const tuesday = 2
71
51
  const wednesday = 3
@@ -111,9 +91,8 @@ function Qrono(...args) {
111
91
  self.context(defaultContext)
112
92
  if (args[0] instanceof Qrono) {
113
93
  const source = args.shift()
114
- for (const key of fields(self)) {
115
- self[key] = source[key]()
116
- }
94
+ self.nativeDate = source.nativeDate()
95
+ self.context(source.context())
117
96
  }
118
97
  if (isObject(args[0]) && !hasDatetimeField(args[0])) {
119
98
  self.context(args.shift())
@@ -373,25 +352,11 @@ Qrono.prototype.offset = function () {
373
352
  : 0
374
353
  }
375
354
 
376
- Qrono.prototype.localtime = function (arg) {
377
- return given(arg) ? this.clone({ localtime: arg }) : this[internal].localtime
378
- }
379
-
380
- Qrono.prototype.disambiguation = function (arg) {
381
- return given(arg)
382
- ? this.clone({ disambiguation: arg })
383
- : this[internal].disambiguation
384
- }
385
-
386
355
  Qrono.prototype.valid = function () {
387
356
  return this[internal].valid()
388
357
  }
389
358
 
390
359
  // Transform
391
- Qrono.prototype.numeric = function () {
392
- return this[internal].nativeDate.getTime()
393
- }
394
-
395
360
  Qrono.prototype.toObject = function () {
396
361
  return {
397
362
  year: this.year(),
@@ -420,15 +385,6 @@ Qrono.prototype.toDate = function (...args) {
420
385
  return new QronoDate(this.clone(...args))
421
386
  }
422
387
 
423
- // Context
424
- Qrono.prototype.asUtc = function () {
425
- return this.clone({ localtime: false })
426
- }
427
-
428
- Qrono.prototype.asLocaltime = function () {
429
- return this.clone({ localtime: true })
430
- }
431
-
432
388
  // Accessor
433
389
  for (const [field, native, offset] of [
434
390
  ['year', 'FullYear', 0],
@@ -558,7 +514,7 @@ Qrono.prototype.startOfDay = function () {
558
514
  const timestamp = this.clone(
559
515
  { disambiguation: 'later' },
560
516
  { hour: 0, minute: 0, second: 0, millisecond: 0 }
561
- ).numeric()
517
+ ).valueOf()
562
518
  return this.clone(timestamp)
563
519
  }
564
520
 
@@ -594,7 +550,7 @@ function plus(sign, ...args) {
594
550
  const arg0 = args[0]
595
551
  const arg1 = args[1]
596
552
  if (Number.isFinite(arg0) && !Number.isFinite(arg1)) {
597
- return this.clone(this.numeric() + arg0)
553
+ return this.clone(this.valueOf() + arg0)
598
554
  }
599
555
  let timeFields = null
600
556
  if (isObject(arg0)) {
@@ -710,10 +666,6 @@ QronoDate.prototype.toDatetime = function () {
710
666
  return qrono(this[internalDate].datetime.toArray())
711
667
  }
712
668
 
713
- QronoDate.prototype.numeric = function () {
714
- return this[internalDate].datetime.numeric() / millisecondsPerDay
715
- }
716
-
717
669
  QronoDate.prototype.toObject = function () {
718
670
  return {
719
671
  year: this.year(),
@@ -734,9 +686,6 @@ QronoDate.prototype.startOfMonth = function () {
734
686
  return new QronoDate(this[internalDate].datetime.startOfMonth())
735
687
  }
736
688
 
737
- QronoDate.prototype.startOfDay = function () {
738
- return this[internalDate].datetime.clone()
739
- }
740
689
  for (const field of ['year', 'month', 'day']) {
741
690
  QronoDate.prototype[field] = function (value) {
742
691
  if (given(value)) {
package/types/qrono.d.ts CHANGED
@@ -217,40 +217,6 @@ declare namespace qrono {
217
217
  */
218
218
  export function context(context: Context): typeof qrono
219
219
 
220
- /**
221
- * Returns whether the global context is localtime.
222
- */
223
- export function localtime(): boolean
224
-
225
- /**
226
- * Sets whether localtime is enabled.
227
- * @param value - True to set the global context localtime.
228
- * @returns The qrono object.
229
- */
230
- export function localtime(value: boolean): typeof qrono
231
-
232
- /**
233
- * Returns the current global disambiguation option.
234
- */
235
- export function disambiguation(): Disambiguation
236
-
237
- /**
238
- * Sets the global disambiguation option.
239
- * @param value - The disambiguation option to set.
240
- * @returns The qrono object.
241
- */
242
- export function disambiguation(value: Disambiguation): typeof qrono
243
-
244
- /**
245
- * Returns new qrono instance with UTC context.
246
- */
247
- export function asUtc(): typeof qrono
248
-
249
- /**
250
- * Returns new qrono instance with localtime context.
251
- */
252
- export function asLocaltime(): typeof qrono
253
-
254
220
  /**
255
221
  * The four disambiguation options for resolving ambiguous local times,
256
222
  * mirroring the Temporal API.
@@ -320,40 +286,11 @@ declare namespace qrono {
320
286
  */
321
287
  offset(): number
322
288
 
323
- /**
324
- * Returns whether localtime is enabled for the Qrono instance.
325
- */
326
- localtime(): boolean
327
-
328
- /**
329
- * Sets whether localtime is enabled for the Qrono instance.
330
- * @param yes - True to enable localtime, false to disable.
331
- * @returns The Qrono instance.
332
- */
333
- localtime(yes: boolean): Qrono
334
-
335
- /**
336
- * Returns the current disambiguation option of the Qrono instance.
337
- */
338
- disambiguation(): Disambiguation
339
-
340
- /**
341
- * Sets the disambiguation option of the Qrono instance.
342
- * @param value - The disambiguation option.
343
- * @returns A new Qrono instance with the updated disambiguation.
344
- */
345
- disambiguation(value: Disambiguation): Qrono
346
-
347
289
  /**
348
290
  * Returns whether the Qrono instance is valid.
349
291
  */
350
292
  valid(): boolean
351
293
 
352
- /**
353
- * Returns the numeric value of the Qrono instance.
354
- */
355
- numeric(): number
356
-
357
294
  /**
358
295
  * Returns the object representation of the Qrono instance.
359
296
  */
@@ -377,18 +314,6 @@ declare namespace qrono {
377
314
  */
378
315
  toDate(): QronoDate
379
316
 
380
- /**
381
- * Sets the context to UTC.
382
- * @returns The Qrono instance.
383
- */
384
- asUtc(): Qrono
385
-
386
- /**
387
- * Sets the context to localtime.
388
- * @returns The Qrono instance.
389
- */
390
- asLocaltime(): Qrono
391
-
392
317
  /**
393
318
  * Returns the year of the Qrono instance.
394
319
  */
@@ -681,11 +606,6 @@ declare namespace qrono {
681
606
  */
682
607
  valid(): boolean
683
608
 
684
- /**
685
- * Returns the numeric value of the QronoDate instance.
686
- */
687
- numeric(): number
688
-
689
609
  /**
690
610
  * Returns the object representation of the QronoDate instance.
691
611
  */
@@ -806,11 +726,6 @@ declare namespace qrono {
806
726
  */
807
727
  startOfMonth(): QronoDate
808
728
 
809
- /**
810
- * Returns a new QronoDate instance representing the start of the day.
811
- */
812
- startOfDay(): Qrono
813
-
814
729
  /**
815
730
  * Returns a new QronoDate instance representing the end of the year.
816
731
  */