mimir-ui-kit 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { useState, useCallback } from "react";
2
- import { Time, Validate } from "./utils.js";
2
+ import { Time, Validate, SECONDS_IN_MILLISECONDS } from "./utils.js";
3
3
  import { useInterval } from "../useInterval/useInterval.js";
4
4
  const DEFAULT_DELAY = 1e3;
5
5
  function getDelayFromExpiryTimestamp(expiryTimestamp) {
@@ -7,7 +7,9 @@ function getDelayFromExpiryTimestamp(expiryTimestamp) {
7
7
  return null;
8
8
  }
9
9
  const seconds = Time.getSecondsFromExpiry(expiryTimestamp);
10
- const extraMilliSeconds = Math.floor((seconds - Math.floor(seconds)) * 1e3);
10
+ const extraMilliSeconds = Math.floor(
11
+ (seconds - Math.floor(seconds)) * SECONDS_IN_MILLISECONDS
12
+ );
11
13
  return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
12
14
  }
13
15
  function useTimer({
@@ -42,7 +44,9 @@ function useTimer({
42
44
  );
43
45
  const resume = useCallback(() => {
44
46
  const time = /* @__PURE__ */ new Date();
45
- time.setMilliseconds(time.getMilliseconds() + seconds * 1e3);
47
+ time.setMilliseconds(
48
+ time.getMilliseconds() + seconds * SECONDS_IN_MILLISECONDS
49
+ );
46
50
  restart(time.getTime(), true);
47
51
  }, [seconds, restart]);
48
52
  const start = useCallback(() => {
@@ -6,6 +6,10 @@ type TTimeObject = {
6
6
  seconds: number;
7
7
  };
8
8
  type TFormattedTime = Omit<TTimeObject, 'totalSeconds' | 'days'>;
9
+ export declare const SECONDS_IN_MINUTE = 60;
10
+ export declare const SECONDS_IN_HOUR: number;
11
+ export declare const SECONDS_IN_DAY: number;
12
+ export declare const SECONDS_IN_MILLISECONDS = 1000;
9
13
  export declare class Time {
10
14
  static getTimeFromSeconds(secs: number): TTimeObject;
11
15
  static getSecondsFromExpiry(expiry: number, shouldRound?: boolean): number;
@@ -1,10 +1,16 @@
1
+ const SECONDS_IN_MINUTE = 60;
2
+ const SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
3
+ const SECONDS_IN_DAY = SECONDS_IN_HOUR * 24;
4
+ const SECONDS_IN_MILLISECONDS = 1e3;
1
5
  class Time {
2
6
  static getTimeFromSeconds(secs) {
3
7
  const totalSeconds = Math.ceil(secs);
4
- const days = Math.floor(totalSeconds / (60 * 60 * 24));
5
- const hours = Math.floor(totalSeconds % (60 * 60 * 24) / (60 * 60));
6
- const minutes = Math.floor(totalSeconds % (60 * 60) / 60);
7
- const seconds = Math.floor(totalSeconds % 60);
8
+ const days = Math.floor(totalSeconds / SECONDS_IN_DAY);
9
+ const hours = Math.floor(totalSeconds % SECONDS_IN_DAY / SECONDS_IN_HOUR);
10
+ const minutes = Math.floor(
11
+ totalSeconds % SECONDS_IN_HOUR / SECONDS_IN_MINUTE
12
+ );
13
+ const seconds = Math.floor(totalSeconds % SECONDS_IN_MINUTE);
8
14
  return {
9
15
  totalSeconds,
10
16
  seconds,
@@ -17,7 +23,7 @@ class Time {
17
23
  const now = (/* @__PURE__ */ new Date()).getTime();
18
24
  const milliSecondsDistance = expiry - now;
19
25
  if (milliSecondsDistance > 0) {
20
- const val = milliSecondsDistance / 1e3;
26
+ const val = milliSecondsDistance / SECONDS_IN_MILLISECONDS;
21
27
  return shouldRound ? Math.round(val) : val;
22
28
  }
23
29
  return 0;
@@ -26,7 +32,7 @@ class Time {
26
32
  const now = (/* @__PURE__ */ new Date()).getTime();
27
33
  const milliSecondsDistance = now - prevTime;
28
34
  if (milliSecondsDistance > 0) {
29
- const val = milliSecondsDistance / 1e3;
35
+ const val = milliSecondsDistance / SECONDS_IN_MILLISECONDS;
30
36
  return shouldRound ? Math.round(val) : val;
31
37
  }
32
38
  return 0;
@@ -34,8 +40,8 @@ class Time {
34
40
  static getSecondsFromTimeNow() {
35
41
  const now = /* @__PURE__ */ new Date();
36
42
  const currentTimestamp = now.getTime();
37
- const offset = now.getTimezoneOffset() * 60;
38
- return currentTimestamp / 1e3 - offset;
43
+ const offset = now.getTimezoneOffset() * SECONDS_IN_MINUTE;
44
+ return currentTimestamp / SECONDS_IN_MILLISECONDS - offset;
39
45
  }
40
46
  static getFormattedTimeFromSeconds(totalSeconds) {
41
47
  const {
@@ -73,6 +79,10 @@ class Validate {
73
79
  }
74
80
  }
75
81
  export {
82
+ SECONDS_IN_DAY,
83
+ SECONDS_IN_HOUR,
84
+ SECONDS_IN_MILLISECONDS,
85
+ SECONDS_IN_MINUTE,
76
86
  Time,
77
87
  Validate
78
88
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mimir-ui-kit",
3
3
  "private": false,
4
- "version": "1.9.0",
4
+ "version": "1.9.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {