@naturalcycles/js-lib 14.220.0 → 14.222.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();
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Promisable } from './typeFest';
|
|
2
3
|
/**
|
|
3
4
|
* Map from String to String (or <T>).
|
|
@@ -192,6 +193,9 @@ export type Integer = number;
|
|
|
192
193
|
* data: (number | null)[]
|
|
193
194
|
*/
|
|
194
195
|
export type NullableNumber = number | null;
|
|
196
|
+
export type NullableString = string | null;
|
|
197
|
+
export type NullableBoolean = boolean | null;
|
|
198
|
+
export type NullableBuffer = Buffer | null;
|
|
195
199
|
/**
|
|
196
200
|
* Used as a compact representation of truthy value.
|
|
197
201
|
* undefined ('' or other short falsy value) should be used as falsy value.
|
|
@@ -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
|
@@ -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()
|
package/src/types.ts
CHANGED
|
@@ -251,6 +251,9 @@ export type Integer = number
|
|
|
251
251
|
* data: (number | null)[]
|
|
252
252
|
*/
|
|
253
253
|
export type NullableNumber = number | null
|
|
254
|
+
export type NullableString = string | null
|
|
255
|
+
export type NullableBoolean = boolean | null
|
|
256
|
+
export type NullableBuffer = Buffer | null
|
|
254
257
|
|
|
255
258
|
/**
|
|
256
259
|
* Used as a compact representation of truthy value.
|