@naturalcycles/js-lib 14.220.0 → 14.221.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.
@@ -176,3 +176,8 @@ export declare function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTi
176
176
  * Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
177
177
  */
178
178
  export declare function localTimeOrNow(d?: LocalTimeInput | null): LocalTime;
179
+ /**
180
+ Convenience function to return current Unix timestamp in seconds.
181
+ Like Date.now(), but in seconds.
182
+ */
183
+ export declare function nowUnix(): UnixTimestampNumber;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localTimeOrNow = exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
3
+ exports.nowUnix = exports.localTimeOrNow = exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
4
4
  const assert_1 = require("../error/assert");
5
5
  const time_util_1 = require("../time/time.util");
6
6
  const localDate_1 = require("./localDate");
@@ -569,6 +569,14 @@ function localTimeOrNow(d) {
569
569
  return d ? LocalTime.of(d) : LocalTime.now();
570
570
  }
571
571
  exports.localTimeOrNow = localTimeOrNow;
572
+ /**
573
+ Convenience function to return current Unix timestamp in seconds.
574
+ Like Date.now(), but in seconds.
575
+ */
576
+ function nowUnix() {
577
+ return Math.floor(Date.now() / 1000);
578
+ }
579
+ exports.nowUnix = nowUnix;
572
580
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
573
581
  function getWeek(date) {
574
582
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
@@ -562,6 +562,13 @@ export function localTimeOrUndefined(d) {
562
562
  export function localTimeOrNow(d) {
563
563
  return d ? LocalTime.of(d) : LocalTime.now();
564
564
  }
565
+ /**
566
+ Convenience function to return current Unix timestamp in seconds.
567
+ Like Date.now(), but in seconds.
568
+ */
569
+ export function nowUnix() {
570
+ return Math.floor(Date.now() / 1000);
571
+ }
565
572
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
566
573
  function getWeek(date) {
567
574
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.220.0",
3
+ "version": "14.221.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -686,6 +686,14 @@ export function localTimeOrNow(d?: LocalTimeInput | null): LocalTime {
686
686
  return d ? LocalTime.of(d) : LocalTime.now()
687
687
  }
688
688
 
689
+ /**
690
+ Convenience function to return current Unix timestamp in seconds.
691
+ Like Date.now(), but in seconds.
692
+ */
693
+ export function nowUnix(): UnixTimestampNumber {
694
+ return Math.floor(Date.now() / 1000)
695
+ }
696
+
689
697
  // based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
690
698
  function getWeek(date: Date): number {
691
699
  const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime()