@jobber/components-native 0.34.0 → 0.35.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.
@@ -0,0 +1,26 @@
1
+ import { getTimezoneOffset } from "date-fns-tz";
2
+
3
+ export type MinutesIncrement = 15 | 30 | 60;
4
+
5
+ /**
6
+ * Rounds up the time by increment.
7
+ * - 15 mins - rounds to the next quarter time of `00:15`, `00:30`, `00:45`,
8
+ * and `01:00`
9
+ * - 30 mins - rounds to the next half hour be it `00:30` or `01:00`
10
+ * - 60 mins - rounds to the next hour. I.e., `02:01` gets rounded up
11
+ * to `03:00`.
12
+ */
13
+ export function roundUpToNearestMinutes(
14
+ date: Date,
15
+ minutes: MinutesIncrement,
16
+ ): Date {
17
+ const ms = 1000 * 60 * minutes;
18
+ return new Date(Math.ceil(date.getTime() / ms) * ms);
19
+ }
20
+
21
+ export function getTimeZoneOffsetInMinutes(
22
+ timeZone: string,
23
+ date?: Date,
24
+ ): number {
25
+ return getTimezoneOffset(timeZone, date) / 1000 / 60;
26
+ }
@@ -0,0 +1,47 @@
1
+ import { set } from "date-fns";
2
+ import {
3
+ MinutesIncrement,
4
+ getTimeZoneOffsetInMinutes,
5
+ roundUpToNearestMinutes,
6
+ } from ".";
7
+
8
+ describe("roundUpToNearestMinutes", () => {
9
+ it.each<[MinutesIncrement, Record<string, number>]>([
10
+ [15, { hours: 1, minutes: 28, expectedMinutes: 30 }],
11
+ [15, { hours: 2, minutes: 3, expectedMinutes: 15 }],
12
+ [30, { hours: 11, minutes: 2, expectedMinutes: 30 }],
13
+ [30, { hours: 11, minutes: 32, expectedHours: 12, expectedMinutes: 0 }],
14
+ [60, { hours: 11, minutes: 59, expectedHours: 12, expectedMinutes: 0 }],
15
+ [60, { hours: 10, minutes: 1, expectedHours: 11, expectedMinutes: 0 }],
16
+ ])(
17
+ "should round up the time to the nearest %s mins",
18
+ (increment, { hours, minutes, expectedMinutes, expectedHours }) => {
19
+ const timeToUpdate = set(new Date(2022, 5, 27), { hours, minutes });
20
+ const time = roundUpToNearestMinutes(timeToUpdate, increment);
21
+
22
+ expect(time.getHours()).toBe(expectedHours || hours);
23
+ expect(time.getMinutes()).toBe(expectedMinutes);
24
+ },
25
+ );
26
+ });
27
+
28
+ describe("getTimeZoneOffsetInMinutes", () => {
29
+ const DSTDate = new Date(2022, 6, 5);
30
+ const nonDSTDate = new Date(2022, 10, 7);
31
+
32
+ it.each<[string, number, Date]>([
33
+ ["America/Edmonton", -6, DSTDate],
34
+ ["America/Edmonton", -7, nonDSTDate],
35
+ ["Africa/Johannesburg", 2, DSTDate],
36
+ ["America/Los_Angeles", -7, DSTDate],
37
+ ["Asia/Manila", 8, DSTDate],
38
+ ["Asia/Manila", 8, nonDSTDate],
39
+ ])(
40
+ "should convert %s to the correct timezone offset for %s",
41
+ (timezone, expectedOffset, date) => {
42
+ const timeZoneOffset = getTimeZoneOffsetInMinutes(timezone, date);
43
+
44
+ expect(timeZoneOffset).toBe(expectedOffset * 60);
45
+ },
46
+ );
47
+ });
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@ export * from "./InputNumber";
23
23
  export * from "./InputPassword";
24
24
  export * from "./InputPressable";
25
25
  export * from "./InputSearch";
26
+ export * from "./InputTime";
26
27
  export * from "./InputText";
27
28
  export * from "./TextList";
28
29
  export * from "./ProgressBar";