littlewing 0.8.0 → 0.8.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.
- package/dist/index.d.ts +37 -33
- package/dist/index.js +44 -37
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -323,19 +323,20 @@ declare namespace exports_date_utils {
|
|
|
323
323
|
* Date utility functions for working with timestamps
|
|
324
324
|
* All functions work with milliseconds since Unix epoch (numbers only)
|
|
325
325
|
*
|
|
326
|
-
* IMPORTANT: All functions use
|
|
327
|
-
*
|
|
328
|
-
*
|
|
326
|
+
* IMPORTANT: All functions use local timezone to match the user's context.
|
|
327
|
+
* In a browser, this reflects the user's timezone. On a server, this reflects
|
|
328
|
+
* the server's configured timezone. This ensures date calculations align with
|
|
329
|
+
* the user's calendar expectations.
|
|
329
330
|
*/
|
|
330
331
|
/**
|
|
331
332
|
* Get current timestamp (milliseconds since Unix epoch)
|
|
332
333
|
*/
|
|
333
334
|
declare const NOW: () => number;
|
|
334
335
|
/**
|
|
335
|
-
* Create timestamp from date components (
|
|
336
|
+
* Create timestamp from date components (local timezone)
|
|
336
337
|
* Year is required, all other parameters default to minimum values
|
|
337
338
|
* Month is 1-based (1 = January, 12 = December)
|
|
338
|
-
* All parameters are interpreted in
|
|
339
|
+
* All parameters are interpreted in local timezone
|
|
339
340
|
*/
|
|
340
341
|
declare const DATE: (year: number, month?: number, day?: number, hour?: number, minute?: number, second?: number) => number;
|
|
341
342
|
/**
|
|
@@ -359,44 +360,44 @@ declare const FROM_MONTHS: (months: number) => number;
|
|
|
359
360
|
*/
|
|
360
361
|
declare const FROM_YEARS: (years: number) => number;
|
|
361
362
|
/**
|
|
362
|
-
* Get the year from a timestamp (
|
|
363
|
+
* Get the year from a timestamp (local timezone)
|
|
363
364
|
*/
|
|
364
365
|
declare const GET_YEAR: (timestamp: number) => number;
|
|
365
366
|
/**
|
|
366
|
-
* Get the month from a timestamp (1-based: 1 = January, 12 = December,
|
|
367
|
+
* Get the month from a timestamp (1-based: 1 = January, 12 = December, local timezone)
|
|
367
368
|
*/
|
|
368
369
|
declare const GET_MONTH: (timestamp: number) => number;
|
|
369
370
|
/**
|
|
370
|
-
* Get the day of month from a timestamp (1-31,
|
|
371
|
+
* Get the day of month from a timestamp (1-31, local timezone)
|
|
371
372
|
*/
|
|
372
373
|
declare const GET_DAY: (timestamp: number) => number;
|
|
373
374
|
/**
|
|
374
|
-
* Get the hour from a timestamp (0-23,
|
|
375
|
+
* Get the hour from a timestamp (0-23, local timezone)
|
|
375
376
|
*/
|
|
376
377
|
declare const GET_HOUR: (timestamp: number) => number;
|
|
377
378
|
/**
|
|
378
|
-
* Get the minute from a timestamp (0-59,
|
|
379
|
+
* Get the minute from a timestamp (0-59, local timezone)
|
|
379
380
|
*/
|
|
380
381
|
declare const GET_MINUTE: (timestamp: number) => number;
|
|
381
382
|
/**
|
|
382
|
-
* Get the second from a timestamp (0-59,
|
|
383
|
+
* Get the second from a timestamp (0-59, local timezone)
|
|
383
384
|
*/
|
|
384
385
|
declare const GET_SECOND: (timestamp: number) => number;
|
|
385
386
|
/**
|
|
386
|
-
* Get the millisecond component from a timestamp (0-999,
|
|
387
|
+
* Get the millisecond component from a timestamp (0-999, local timezone)
|
|
387
388
|
*/
|
|
388
389
|
declare const GET_MILLISECOND: (timestamp: number) => number;
|
|
389
390
|
/**
|
|
390
|
-
* Get the day of week from a timestamp (0 = Sunday, 6 = Saturday,
|
|
391
|
+
* Get the day of week from a timestamp (0 = Sunday, 6 = Saturday, local timezone)
|
|
391
392
|
*/
|
|
392
393
|
declare const GET_WEEKDAY: (timestamp: number) => number;
|
|
393
394
|
/**
|
|
394
|
-
* Get the day of year (1-366) from a timestamp (
|
|
395
|
+
* Get the day of year (1-366) from a timestamp (local timezone)
|
|
395
396
|
* January 1st = 1, December 31st = 365 or 366 (leap year)
|
|
396
397
|
*/
|
|
397
398
|
declare const GET_DAY_OF_YEAR: (timestamp: number) => number;
|
|
398
399
|
/**
|
|
399
|
-
* Get the quarter (1-4) from a timestamp (
|
|
400
|
+
* Get the quarter (1-4) from a timestamp (local timezone)
|
|
400
401
|
*/
|
|
401
402
|
declare const GET_QUARTER: (timestamp: number) => number;
|
|
402
403
|
/**
|
|
@@ -412,15 +413,18 @@ declare const DIFFERENCE_IN_MINUTES: (ts1: number, ts2: number) => number;
|
|
|
412
413
|
*/
|
|
413
414
|
declare const DIFFERENCE_IN_HOURS: (ts1: number, ts2: number) => number;
|
|
414
415
|
/**
|
|
415
|
-
* Get the
|
|
416
|
+
* Get the difference in calendar days between two timestamps
|
|
417
|
+
* Counts the number of calendar day boundaries crossed, not 24-hour periods
|
|
418
|
+
* Example: Nov 7 at 11:59 PM to Nov 8 at 12:01 AM = 1 day (different calendar days)
|
|
416
419
|
*/
|
|
417
420
|
declare const DIFFERENCE_IN_DAYS: (ts1: number, ts2: number) => number;
|
|
418
421
|
/**
|
|
419
|
-
* Get the
|
|
422
|
+
* Get the difference in calendar weeks between two timestamps
|
|
423
|
+
* Counts the number of week boundaries crossed (based on calendar days)
|
|
420
424
|
*/
|
|
421
425
|
declare const DIFFERENCE_IN_WEEKS: (ts1: number, ts2: number) => number;
|
|
422
426
|
/**
|
|
423
|
-
* Get the number of full calendar months between two timestamps (
|
|
427
|
+
* Get the number of full calendar months between two timestamps (local timezone)
|
|
424
428
|
* Counts complete months where the same day-of-month has been reached
|
|
425
429
|
*
|
|
426
430
|
* Examples:
|
|
@@ -431,7 +435,7 @@ declare const DIFFERENCE_IN_WEEKS: (ts1: number, ts2: number) => number;
|
|
|
431
435
|
*/
|
|
432
436
|
declare const DIFFERENCE_IN_MONTHS: (ts1: number, ts2: number) => number;
|
|
433
437
|
/**
|
|
434
|
-
* Get the number of full calendar years between two timestamps (
|
|
438
|
+
* Get the number of full calendar years between two timestamps (local timezone)
|
|
435
439
|
* Counts complete years where the same month and day have been reached
|
|
436
440
|
*
|
|
437
441
|
* Examples:
|
|
@@ -442,62 +446,62 @@ declare const DIFFERENCE_IN_MONTHS: (ts1: number, ts2: number) => number;
|
|
|
442
446
|
*/
|
|
443
447
|
declare const DIFFERENCE_IN_YEARS: (ts1: number, ts2: number) => number;
|
|
444
448
|
/**
|
|
445
|
-
* Get the start of day (00:00:00.000
|
|
449
|
+
* Get the start of day (00:00:00.000 local time) for a given timestamp
|
|
446
450
|
*/
|
|
447
451
|
declare const START_OF_DAY: (timestamp: number) => number;
|
|
448
452
|
/**
|
|
449
|
-
* Get the end of day (23:59:59.999
|
|
453
|
+
* Get the end of day (23:59:59.999 local time) for a given timestamp
|
|
450
454
|
*/
|
|
451
455
|
declare const END_OF_DAY: (timestamp: number) => number;
|
|
452
456
|
/**
|
|
453
|
-
* Get the start of week (Sunday at 00:00:00.000
|
|
457
|
+
* Get the start of week (Sunday at 00:00:00.000 local time) for a given timestamp
|
|
454
458
|
*/
|
|
455
459
|
declare const START_OF_WEEK: (timestamp: number) => number;
|
|
456
460
|
/**
|
|
457
|
-
* Get the start of month (1st day at 00:00:00.000
|
|
461
|
+
* Get the start of month (1st day at 00:00:00.000 local time) for a given timestamp
|
|
458
462
|
*/
|
|
459
463
|
declare const START_OF_MONTH: (timestamp: number) => number;
|
|
460
464
|
/**
|
|
461
|
-
* Get the end of month (last day at 23:59:59.999
|
|
465
|
+
* Get the end of month (last day at 23:59:59.999 local time) for a given timestamp
|
|
462
466
|
*/
|
|
463
467
|
declare const END_OF_MONTH: (timestamp: number) => number;
|
|
464
468
|
/**
|
|
465
|
-
* Get the start of year (Jan 1st at 00:00:00.000
|
|
469
|
+
* Get the start of year (Jan 1st at 00:00:00.000 local time) for a given timestamp
|
|
466
470
|
*/
|
|
467
471
|
declare const START_OF_YEAR: (timestamp: number) => number;
|
|
468
472
|
/**
|
|
469
|
-
* Get the end of year (Dec 31st at 23:59:59.999
|
|
473
|
+
* Get the end of year (Dec 31st at 23:59:59.999 local time) for a given timestamp
|
|
470
474
|
*/
|
|
471
475
|
declare const END_OF_YEAR: (timestamp: number) => number;
|
|
472
476
|
/**
|
|
473
|
-
* Add days to a timestamp (
|
|
477
|
+
* Add days to a timestamp (local timezone)
|
|
474
478
|
*/
|
|
475
479
|
declare const ADD_DAYS: (timestamp: number, days: number) => number;
|
|
476
480
|
/**
|
|
477
|
-
* Add months to a timestamp (handles variable month lengths correctly,
|
|
481
|
+
* Add months to a timestamp (handles variable month lengths correctly, local timezone)
|
|
478
482
|
*/
|
|
479
483
|
declare const ADD_MONTHS: (timestamp: number, months: number) => number;
|
|
480
484
|
/**
|
|
481
|
-
* Add years to a timestamp (
|
|
485
|
+
* Add years to a timestamp (local timezone)
|
|
482
486
|
*/
|
|
483
487
|
declare const ADD_YEARS: (timestamp: number, years: number) => number;
|
|
484
488
|
/**
|
|
485
|
-
* Check if two timestamps are on the same calendar day (
|
|
489
|
+
* Check if two timestamps are on the same calendar day (local timezone)
|
|
486
490
|
* Returns 1 if true, 0 if false
|
|
487
491
|
*/
|
|
488
492
|
declare const IS_SAME_DAY: (ts1: number, ts2: number) => number;
|
|
489
493
|
/**
|
|
490
|
-
* Check if timestamp falls on a weekend (Saturday or Sunday,
|
|
494
|
+
* Check if timestamp falls on a weekend (Saturday or Sunday, local timezone)
|
|
491
495
|
* Returns 1 if true, 0 if false
|
|
492
496
|
*/
|
|
493
497
|
declare const IS_WEEKEND: (timestamp: number) => number;
|
|
494
498
|
/**
|
|
495
|
-
* Check if timestamp is in a leap year (
|
|
499
|
+
* Check if timestamp is in a leap year (local timezone)
|
|
496
500
|
* Returns 1 if true, 0 if false
|
|
497
501
|
*/
|
|
498
502
|
declare const IS_LEAP_YEAR: (timestamp: number) => number;
|
|
499
503
|
/**
|
|
500
|
-
* Get the start of quarter for a given timestamp (
|
|
504
|
+
* Get the start of quarter for a given timestamp (local timezone)
|
|
501
505
|
*/
|
|
502
506
|
declare const START_OF_QUARTER: (timestamp: number) => number;
|
|
503
507
|
/**
|
package/dist/index.js
CHANGED
|
@@ -449,45 +449,52 @@ __export(exports_date_utils, {
|
|
|
449
449
|
ADD_DAYS: () => ADD_DAYS
|
|
450
450
|
});
|
|
451
451
|
var NOW = () => Date.now();
|
|
452
|
-
var DATE = (year, month = 1, day = 1, hour = 0, minute = 0, second = 0) => Date
|
|
452
|
+
var DATE = (year, month = 1, day = 1, hour = 0, minute = 0, second = 0) => new Date(year, month - 1, day, hour, minute, second).getTime();
|
|
453
453
|
var FROM_DAYS = (d) => d * 24 * 60 * 60 * 1000;
|
|
454
454
|
var FROM_WEEKS = (w) => w * 7 * 24 * 60 * 60 * 1000;
|
|
455
455
|
var FROM_MONTHS = (months) => months * 30 * 24 * 60 * 60 * 1000;
|
|
456
456
|
var FROM_YEARS = (years) => years * 365 * 24 * 60 * 60 * 1000;
|
|
457
|
-
var GET_YEAR = (timestamp) => new Date(timestamp).
|
|
458
|
-
var GET_MONTH = (timestamp) => new Date(timestamp).
|
|
459
|
-
var GET_DAY = (timestamp) => new Date(timestamp).
|
|
460
|
-
var GET_HOUR = (timestamp) => new Date(timestamp).
|
|
461
|
-
var GET_MINUTE = (timestamp) => new Date(timestamp).
|
|
462
|
-
var GET_SECOND = (timestamp) => new Date(timestamp).
|
|
463
|
-
var GET_MILLISECOND = (timestamp) => new Date(timestamp).
|
|
464
|
-
var GET_WEEKDAY = (timestamp) => new Date(timestamp).
|
|
457
|
+
var GET_YEAR = (timestamp) => new Date(timestamp).getFullYear();
|
|
458
|
+
var GET_MONTH = (timestamp) => new Date(timestamp).getMonth() + 1;
|
|
459
|
+
var GET_DAY = (timestamp) => new Date(timestamp).getDate();
|
|
460
|
+
var GET_HOUR = (timestamp) => new Date(timestamp).getHours();
|
|
461
|
+
var GET_MINUTE = (timestamp) => new Date(timestamp).getMinutes();
|
|
462
|
+
var GET_SECOND = (timestamp) => new Date(timestamp).getSeconds();
|
|
463
|
+
var GET_MILLISECOND = (timestamp) => new Date(timestamp).getMilliseconds();
|
|
464
|
+
var GET_WEEKDAY = (timestamp) => new Date(timestamp).getDay();
|
|
465
465
|
var GET_DAY_OF_YEAR = (timestamp) => {
|
|
466
466
|
const date = new Date(timestamp);
|
|
467
|
-
const year = date.
|
|
468
|
-
const startOfYear = Date
|
|
467
|
+
const year = date.getFullYear();
|
|
468
|
+
const startOfYear = new Date(year, 0, 1).getTime();
|
|
469
469
|
const diff = timestamp - startOfYear;
|
|
470
470
|
const oneDay = 86400000;
|
|
471
471
|
return Math.floor(diff / oneDay) + 1;
|
|
472
472
|
};
|
|
473
473
|
var GET_QUARTER = (timestamp) => {
|
|
474
|
-
const month = new Date(timestamp).
|
|
474
|
+
const month = new Date(timestamp).getMonth();
|
|
475
475
|
return Math.floor(month / 3) + 1;
|
|
476
476
|
};
|
|
477
|
-
var DIFFERENCE_IN_SECONDS = (ts1, ts2) => Math.
|
|
478
|
-
var DIFFERENCE_IN_MINUTES = (ts1, ts2) => Math.
|
|
479
|
-
var DIFFERENCE_IN_HOURS = (ts1, ts2) => Math.
|
|
480
|
-
var DIFFERENCE_IN_DAYS = (ts1, ts2) =>
|
|
481
|
-
|
|
477
|
+
var DIFFERENCE_IN_SECONDS = (ts1, ts2) => Math.ceil(Math.abs(ts1 - ts2) / 1000);
|
|
478
|
+
var DIFFERENCE_IN_MINUTES = (ts1, ts2) => Math.ceil(Math.abs(ts1 - ts2) / (60 * 1000));
|
|
479
|
+
var DIFFERENCE_IN_HOURS = (ts1, ts2) => Math.ceil(Math.abs(ts1 - ts2) / (60 * 60 * 1000));
|
|
480
|
+
var DIFFERENCE_IN_DAYS = (ts1, ts2) => {
|
|
481
|
+
const day1 = START_OF_DAY(ts1);
|
|
482
|
+
const day2 = START_OF_DAY(ts2);
|
|
483
|
+
return Math.floor(Math.abs(day1 - day2) / (24 * 60 * 60 * 1000));
|
|
484
|
+
};
|
|
485
|
+
var DIFFERENCE_IN_WEEKS = (ts1, ts2) => {
|
|
486
|
+
const days = DIFFERENCE_IN_DAYS(ts1, ts2);
|
|
487
|
+
return Math.floor(days / 7);
|
|
488
|
+
};
|
|
482
489
|
var DIFFERENCE_IN_MONTHS = (ts1, ts2) => {
|
|
483
490
|
const smaller = Math.min(ts1, ts2);
|
|
484
491
|
const larger = Math.max(ts1, ts2);
|
|
485
492
|
const date1 = new Date(smaller);
|
|
486
493
|
const date2 = new Date(larger);
|
|
487
|
-
const yearDiff = date2.
|
|
488
|
-
const monthDiff = date2.
|
|
494
|
+
const yearDiff = date2.getFullYear() - date1.getFullYear();
|
|
495
|
+
const monthDiff = date2.getMonth() - date1.getMonth();
|
|
489
496
|
let months = yearDiff * 12 + monthDiff;
|
|
490
|
-
if (date2.
|
|
497
|
+
if (date2.getDate() < date1.getDate()) {
|
|
491
498
|
months--;
|
|
492
499
|
}
|
|
493
500
|
return months;
|
|
@@ -497,65 +504,65 @@ var DIFFERENCE_IN_YEARS = (ts1, ts2) => {
|
|
|
497
504
|
};
|
|
498
505
|
var START_OF_DAY = (timestamp) => {
|
|
499
506
|
const date = new Date(timestamp);
|
|
500
|
-
return Date
|
|
507
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0).getTime();
|
|
501
508
|
};
|
|
502
509
|
var END_OF_DAY = (timestamp) => {
|
|
503
510
|
const date = new Date(timestamp);
|
|
504
|
-
return Date
|
|
511
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999).getTime();
|
|
505
512
|
};
|
|
506
513
|
var START_OF_WEEK = (timestamp) => {
|
|
507
514
|
const date = new Date(timestamp);
|
|
508
|
-
const dayOfWeek = date.
|
|
509
|
-
const currentDay = date.
|
|
515
|
+
const dayOfWeek = date.getDay();
|
|
516
|
+
const currentDay = date.getDate();
|
|
510
517
|
const startDay = currentDay - dayOfWeek;
|
|
511
|
-
return Date
|
|
518
|
+
return new Date(date.getFullYear(), date.getMonth(), startDay, 0, 0, 0, 0).getTime();
|
|
512
519
|
};
|
|
513
520
|
var START_OF_MONTH = (timestamp) => {
|
|
514
521
|
const date = new Date(timestamp);
|
|
515
|
-
return Date
|
|
522
|
+
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0).getTime();
|
|
516
523
|
};
|
|
517
524
|
var END_OF_MONTH = (timestamp) => {
|
|
518
525
|
const date = new Date(timestamp);
|
|
519
|
-
return Date
|
|
526
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999).getTime();
|
|
520
527
|
};
|
|
521
528
|
var START_OF_YEAR = (timestamp) => {
|
|
522
529
|
const date = new Date(timestamp);
|
|
523
|
-
return Date
|
|
530
|
+
return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0).getTime();
|
|
524
531
|
};
|
|
525
532
|
var END_OF_YEAR = (timestamp) => {
|
|
526
533
|
const date = new Date(timestamp);
|
|
527
|
-
return Date
|
|
534
|
+
return new Date(date.getFullYear(), 11, 31, 23, 59, 59, 999).getTime();
|
|
528
535
|
};
|
|
529
536
|
var ADD_DAYS = (timestamp, days) => {
|
|
530
537
|
const date = new Date(timestamp);
|
|
531
|
-
return Date
|
|
538
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + days, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()).getTime();
|
|
532
539
|
};
|
|
533
540
|
var ADD_MONTHS = (timestamp, months) => {
|
|
534
541
|
const date = new Date(timestamp);
|
|
535
|
-
return Date
|
|
542
|
+
return new Date(date.getFullYear(), date.getMonth() + months, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()).getTime();
|
|
536
543
|
};
|
|
537
544
|
var ADD_YEARS = (timestamp, years) => {
|
|
538
545
|
const date = new Date(timestamp);
|
|
539
|
-
return Date
|
|
546
|
+
return new Date(date.getFullYear() + years, date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()).getTime();
|
|
540
547
|
};
|
|
541
548
|
var IS_SAME_DAY = (ts1, ts2) => {
|
|
542
549
|
const date1 = new Date(ts1);
|
|
543
550
|
const date2 = new Date(ts2);
|
|
544
|
-
return date1.
|
|
551
|
+
return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate() ? 1 : 0;
|
|
545
552
|
};
|
|
546
553
|
var IS_WEEKEND = (timestamp) => {
|
|
547
|
-
const day = new Date(timestamp).
|
|
554
|
+
const day = new Date(timestamp).getDay();
|
|
548
555
|
return day === 0 || day === 6 ? 1 : 0;
|
|
549
556
|
};
|
|
550
557
|
var IS_LEAP_YEAR = (timestamp) => {
|
|
551
|
-
const year = new Date(timestamp).
|
|
558
|
+
const year = new Date(timestamp).getFullYear();
|
|
552
559
|
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0 ? 1 : 0;
|
|
553
560
|
};
|
|
554
561
|
var START_OF_QUARTER = (timestamp) => {
|
|
555
562
|
const date = new Date(timestamp);
|
|
556
|
-
const month = date.
|
|
563
|
+
const month = date.getMonth();
|
|
557
564
|
const quarterStartMonth = Math.floor(month / 3) * 3;
|
|
558
|
-
return Date
|
|
565
|
+
return new Date(date.getFullYear(), quarterStartMonth, 1, 0, 0, 0, 0).getTime();
|
|
559
566
|
};
|
|
560
567
|
// src/defaults.ts
|
|
561
568
|
var defaultContext = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlewing",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "A minimal, high-performance arithmetic expression language with lexer, parser, and executor. Optimized for browsers with zero dependencies and type-safe execution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arithmetic",
|