@churchapps/apphelper 0.5.0 → 0.5.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.
Files changed (100) hide show
  1. package/dist/components/Loading.js +36 -36
  2. package/dist/components/notes/Notes.js +27 -27
  3. package/dist/helpers/AnalyticsHelper.d.ts.map +1 -1
  4. package/dist/helpers/AnalyticsHelper.js +21 -6
  5. package/dist/helpers/AnalyticsHelper.js.map +1 -1
  6. package/dist/helpers/UserHelper.d.ts.map +1 -1
  7. package/dist/helpers/UserHelper.js +4 -1
  8. package/dist/helpers/UserHelper.js.map +1 -1
  9. package/dist/public/css/cropper.css +309 -309
  10. package/dist/public/css/styles.css +111 -111
  11. package/dist/public/locales/de.json +270 -0
  12. package/dist/public/locales/en.json +277 -0
  13. package/dist/public/locales/es.json +272 -0
  14. package/dist/public/locales/fr.json +270 -0
  15. package/dist/public/locales/hi.json +270 -0
  16. package/dist/public/locales/it.json +270 -0
  17. package/dist/public/locales/ko.json +270 -0
  18. package/dist/public/locales/no.json +270 -0
  19. package/dist/public/locales/pt.json +270 -0
  20. package/dist/public/locales/ru.json +270 -0
  21. package/dist/public/locales/tl.json +270 -0
  22. package/dist/public/locales/zh.json +270 -0
  23. package/package.json +72 -72
  24. package/public/css/cropper.css +309 -309
  25. package/public/css/styles.css +111 -111
  26. package/public/locales/de.json +269 -269
  27. package/public/locales/en.json +276 -276
  28. package/public/locales/es.json +272 -272
  29. package/public/locales/fr.json +269 -269
  30. package/public/locales/hi.json +269 -269
  31. package/public/locales/it.json +269 -269
  32. package/public/locales/ko.json +269 -269
  33. package/public/locales/no.json +269 -269
  34. package/public/locales/pt.json +269 -269
  35. package/public/locales/ru.json +269 -269
  36. package/public/locales/tl.json +269 -269
  37. package/public/locales/zh.json +269 -269
  38. package/src/components/DisplayBox.tsx +83 -83
  39. package/src/components/ErrorMessages.tsx +28 -28
  40. package/src/components/ExportLink.tsx +81 -81
  41. package/src/components/FloatingSupport.tsx +18 -18
  42. package/src/components/FormCardPayment.tsx +184 -184
  43. package/src/components/FormSubmissionEdit.tsx +168 -168
  44. package/src/components/HelpIcon.tsx +12 -12
  45. package/src/components/ImageEditor.tsx +161 -161
  46. package/src/components/InputBox.tsx +96 -96
  47. package/src/components/Loading.tsx +77 -77
  48. package/src/components/PageHeader.tsx +110 -110
  49. package/src/components/PersonAvatar.tsx +77 -77
  50. package/src/components/QuestionEdit.tsx +99 -99
  51. package/src/components/SmallButton.tsx +42 -42
  52. package/src/components/SupportModal.tsx +32 -32
  53. package/src/components/TabPanel.tsx +28 -28
  54. package/src/components/gallery/GalleryModal.tsx +173 -173
  55. package/src/components/gallery/StockPhotos.tsx +95 -95
  56. package/src/components/gallery/index.ts +1 -1
  57. package/src/components/header/Banner.tsx +11 -11
  58. package/src/components/header/PrimaryMenu.tsx +100 -100
  59. package/src/components/header/SecondaryMenu.tsx +23 -23
  60. package/src/components/header/SecondaryMenuAlt.tsx +40 -40
  61. package/src/components/header/SiteHeader.tsx +207 -207
  62. package/src/components/header/SupportDrawer.tsx +111 -111
  63. package/src/components/header/index.tsx +2 -2
  64. package/src/components/index.tsx +20 -20
  65. package/src/components/notes/AddNote.tsx +180 -180
  66. package/src/components/notes/Note.tsx +68 -68
  67. package/src/components/notes/Notes.tsx +208 -208
  68. package/src/components/notes/index.ts +3 -3
  69. package/src/components/wrapper/AppList.tsx +19 -19
  70. package/src/components/wrapper/ChurchList.tsx +154 -154
  71. package/src/components/wrapper/NavItem.tsx +47 -47
  72. package/src/components/wrapper/NewPrivateMessage.tsx +253 -253
  73. package/src/components/wrapper/Notifications.tsx +223 -223
  74. package/src/components/wrapper/PrivateMessageDetails.tsx +112 -112
  75. package/src/components/wrapper/PrivateMessages.tsx +576 -576
  76. package/src/components/wrapper/UserMenu.tsx +383 -383
  77. package/src/components/wrapper/index.tsx +8 -8
  78. package/src/helpers/AnalyticsHelper.ts +44 -32
  79. package/src/helpers/AppearanceHelper.ts +73 -73
  80. package/src/helpers/ArrayHelper.ts +87 -87
  81. package/src/helpers/CurrencyHelper.ts +10 -10
  82. package/src/helpers/DateHelper.ts +104 -104
  83. package/src/helpers/ErrorHelper.ts +43 -43
  84. package/src/helpers/EventHelper.ts +49 -49
  85. package/src/helpers/FileHelper.ts +31 -31
  86. package/src/helpers/Locale.ts +457 -457
  87. package/src/helpers/NotificationService.ts +296 -296
  88. package/src/helpers/PersonHelper.ts +62 -62
  89. package/src/helpers/SlugHelper.ts +37 -37
  90. package/src/helpers/SocketHelper.ts +296 -296
  91. package/src/helpers/UniqueIdHelper.ts +36 -36
  92. package/src/helpers/UserHelper.ts +107 -104
  93. package/src/helpers/createEmotionCache.ts +17 -17
  94. package/src/helpers/index.ts +58 -58
  95. package/src/hooks/index.ts +3 -3
  96. package/src/hooks/useMountedState.ts +16 -16
  97. package/src/hooks/useNotifications.ts +93 -93
  98. package/src/index.ts +2 -2
  99. package/src/types/interface-extensions.d.ts +11 -11
  100. package/tsconfig.json +31 -31
@@ -1,8 +1,8 @@
1
- export { NavItem } from "./NavItem";
2
- export { AppList } from "./AppList";
3
- export { ChurchList } from "./ChurchList";
4
- export { UserMenu } from "./UserMenu";
5
- export { NewPrivateMessage } from "./NewPrivateMessage";
6
- export { PrivateMessages } from "./PrivateMessages";
7
- export { PrivateMessageDetails } from "./PrivateMessageDetails";
8
- export { Notifications } from "./Notifications";
1
+ export { NavItem } from "./NavItem";
2
+ export { AppList } from "./AppList";
3
+ export { ChurchList } from "./ChurchList";
4
+ export { UserMenu } from "./UserMenu";
5
+ export { NewPrivateMessage } from "./NewPrivateMessage";
6
+ export { PrivateMessages } from "./PrivateMessages";
7
+ export { PrivateMessageDetails } from "./PrivateMessageDetails";
8
+ export { Notifications } from "./Notifications";
@@ -1,32 +1,44 @@
1
- import ReactGA from "react-ga4";
2
- import { CommonEnvironmentHelper, UserHelper } from "@churchapps/helpers";
3
-
4
- export class AnalyticsHelper {
5
-
6
- static init = () => {
7
- if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
8
- ReactGA.initialize([{trackingId: CommonEnvironmentHelper.GoogleAnalyticsTag}]);
9
- AnalyticsHelper.logPageView();
10
- }
11
- }
12
-
13
- static logPageView = () => {
14
- if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
15
- this.setChurchKey();
16
- ReactGA.send({ hitType: "pageview", page: window.location.pathname + window.location.search });
17
- }
18
- }
19
-
20
- static logEvent = (category: string, action: string, label?:string) => {
21
- if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
22
- this.setChurchKey();
23
- ReactGA.event({ category, action, label });
24
- }
25
- }
26
-
27
- private static setChurchKey = () => {
28
- const churchKey = UserHelper?.currentUserChurch?.church?.subDomain;
29
- if (churchKey) ReactGA.set({church_key: churchKey });
30
- }
31
-
32
- }
1
+ import ReactGA from "react-ga4";
2
+ import { CommonEnvironmentHelper, UserHelper } from "@churchapps/helpers";
3
+
4
+ export class AnalyticsHelper {
5
+
6
+ static init = () => {
7
+ if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
8
+ try {
9
+ ReactGA.initialize([{trackingId: CommonEnvironmentHelper.GoogleAnalyticsTag}]);
10
+ AnalyticsHelper.logPageView();
11
+ } catch (error) {
12
+ console.warn('Analytics initialization failed:', error);
13
+ }
14
+ }
15
+ }
16
+
17
+ static logPageView = () => {
18
+ if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
19
+ try {
20
+ this.setChurchKey();
21
+ ReactGA.send({ hitType: "pageview", page: window.location.pathname + window.location.search });
22
+ } catch (error) {
23
+ console.warn('Analytics page view logging failed:', error);
24
+ }
25
+ }
26
+ }
27
+
28
+ static logEvent = (category: string, action: string, label?:string) => {
29
+ if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
30
+ try {
31
+ this.setChurchKey();
32
+ ReactGA.event({ category, action, label });
33
+ } catch (error) {
34
+ console.warn('Analytics event logging failed:', error);
35
+ }
36
+ }
37
+ }
38
+
39
+ private static setChurchKey = () => {
40
+ const churchKey = UserHelper?.currentUserChurch?.church?.subDomain;
41
+ if (churchKey) ReactGA.set({church_key: churchKey });
42
+ }
43
+
44
+ }
@@ -1,73 +1,73 @@
1
-
2
- export type AppearanceInterface = { wrapperBackground?: string, logoLight?: string, logoDark?: string, favicon_400x400?: string, favicon_16x16?: string, ogImage?: string }
3
-
4
- export class AppearanceHelper {
5
-
6
- public static getLogoDark(appearanceSettings: AppearanceInterface, defaultLogo: string) {
7
- return (appearanceSettings?.logoDark) ? appearanceSettings.logoDark : defaultLogo;
8
- }
9
-
10
- public static getLogoLight(appearanceSettings: AppearanceInterface, defaultLogo: string) {
11
- return (appearanceSettings?.logoLight) ? appearanceSettings.logoLight : defaultLogo;
12
- }
13
-
14
- public static getFavicon(appearanceSettings: AppearanceInterface, size: "400" | "16") {
15
- if (size === "400") {
16
- return appearanceSettings?.favicon_400x400;
17
- }
18
-
19
- if (size === "16") {
20
- return appearanceSettings?.favicon_16x16;
21
- }
22
-
23
- return;
24
- }
25
-
26
- public static getLogo(appearanceSettings: AppearanceInterface, defaultLogoLight: string, defaultLogoDark: string, backgroundColor: string) {
27
- const isDark = (appearanceSettings.logoDark) ? this.isDark(backgroundColor) : false;
28
- if (isDark) return this.getLogoDark(appearanceSettings, defaultLogoDark);
29
- else return this.getLogoLight(appearanceSettings, defaultLogoLight);
30
- }
31
-
32
- public static getLogoByTextColor(logoLight: string, logoDark: string, textColor: string) {
33
- return (this.isDark(textColor)) ? logoLight : logoDark;
34
- }
35
-
36
- private static isDark(backgroundColor: string) {
37
- let valid = false;
38
- let r = 0;
39
- let g = 0;
40
- let b = 0;
41
-
42
- if (backgroundColor.match(/#[0-9a-fA-F{6}]/)) {
43
- r = this.getHexValue(backgroundColor.substring(1, 2));
44
- g = this.getHexValue(backgroundColor.substring(3, 4));
45
- b = this.getHexValue(backgroundColor.substring(5, 6));
46
- valid = true;
47
- } else if (backgroundColor.match(/#[0-9a-fA-F{3}]/)) {
48
- r = this.getHexValue(backgroundColor.substring(1, 1));
49
- g = this.getHexValue(backgroundColor.substring(2, 2));
50
- b = this.getHexValue(backgroundColor.substring(3, 3));
51
- valid = true;
52
- }
53
-
54
- if (!valid) return false;
55
- else {
56
- //HSP brightness formula. Some colors have a bigger impact on our perceived brightness than others.
57
- const rWeight = .299 * Math.pow(r, 2);
58
- const gWeight = .587 * Math.pow(g, 2);
59
- const bWeight = .114 * Math.pow(b, 2);
60
- const brightness = Math.sqrt(rWeight + gWeight + bWeight);
61
- //return brightness < 128; //
62
- return brightness < 156;
63
- }
64
-
65
- }
66
-
67
- private static getHexValue(hex: string) {
68
- let result = parseInt(hex, 16);
69
- if (hex.length === 1) result = result * 16;
70
- return result;
71
- }
72
-
73
- }
1
+
2
+ export type AppearanceInterface = { wrapperBackground?: string, logoLight?: string, logoDark?: string, favicon_400x400?: string, favicon_16x16?: string, ogImage?: string }
3
+
4
+ export class AppearanceHelper {
5
+
6
+ public static getLogoDark(appearanceSettings: AppearanceInterface, defaultLogo: string) {
7
+ return (appearanceSettings?.logoDark) ? appearanceSettings.logoDark : defaultLogo;
8
+ }
9
+
10
+ public static getLogoLight(appearanceSettings: AppearanceInterface, defaultLogo: string) {
11
+ return (appearanceSettings?.logoLight) ? appearanceSettings.logoLight : defaultLogo;
12
+ }
13
+
14
+ public static getFavicon(appearanceSettings: AppearanceInterface, size: "400" | "16") {
15
+ if (size === "400") {
16
+ return appearanceSettings?.favicon_400x400;
17
+ }
18
+
19
+ if (size === "16") {
20
+ return appearanceSettings?.favicon_16x16;
21
+ }
22
+
23
+ return;
24
+ }
25
+
26
+ public static getLogo(appearanceSettings: AppearanceInterface, defaultLogoLight: string, defaultLogoDark: string, backgroundColor: string) {
27
+ const isDark = (appearanceSettings.logoDark) ? this.isDark(backgroundColor) : false;
28
+ if (isDark) return this.getLogoDark(appearanceSettings, defaultLogoDark);
29
+ else return this.getLogoLight(appearanceSettings, defaultLogoLight);
30
+ }
31
+
32
+ public static getLogoByTextColor(logoLight: string, logoDark: string, textColor: string) {
33
+ return (this.isDark(textColor)) ? logoLight : logoDark;
34
+ }
35
+
36
+ private static isDark(backgroundColor: string) {
37
+ let valid = false;
38
+ let r = 0;
39
+ let g = 0;
40
+ let b = 0;
41
+
42
+ if (backgroundColor.match(/#[0-9a-fA-F{6}]/)) {
43
+ r = this.getHexValue(backgroundColor.substring(1, 2));
44
+ g = this.getHexValue(backgroundColor.substring(3, 4));
45
+ b = this.getHexValue(backgroundColor.substring(5, 6));
46
+ valid = true;
47
+ } else if (backgroundColor.match(/#[0-9a-fA-F{3}]/)) {
48
+ r = this.getHexValue(backgroundColor.substring(1, 1));
49
+ g = this.getHexValue(backgroundColor.substring(2, 2));
50
+ b = this.getHexValue(backgroundColor.substring(3, 3));
51
+ valid = true;
52
+ }
53
+
54
+ if (!valid) return false;
55
+ else {
56
+ //HSP brightness formula. Some colors have a bigger impact on our perceived brightness than others.
57
+ const rWeight = .299 * Math.pow(r, 2);
58
+ const gWeight = .587 * Math.pow(g, 2);
59
+ const bWeight = .114 * Math.pow(b, 2);
60
+ const brightness = Math.sqrt(rWeight + gWeight + bWeight);
61
+ //return brightness < 128; //
62
+ return brightness < 156;
63
+ }
64
+
65
+ }
66
+
67
+ private static getHexValue(hex: string) {
68
+ let result = parseInt(hex, 16);
69
+ if (hex.length === 1) result = result * 16;
70
+ return result;
71
+ }
72
+
73
+ }
@@ -1,87 +1,87 @@
1
- import { UniqueIdHelper } from "./UniqueIdHelper";
2
-
3
- export class ArrayHelper {
4
-
5
- static getIds(array: any[], propertyName: string) {
6
- const result: string[] = [];
7
- for (const item of array) {
8
- const id = item[propertyName]?.toString();
9
- if (!UniqueIdHelper.isMissing(id) && result.indexOf(id) === -1) result.push(id);
10
- }
11
- return result;
12
- }
13
-
14
- static sortBy(array: any[], propertyName: string, descending: boolean = false) {
15
- array.sort((a, b) => {
16
- const valA = a[propertyName];
17
- const valB = b[propertyName];
18
- if (valA < valB) return descending ? 1 : -1;
19
- else return descending ? -1 : 1;
20
- });
21
- }
22
-
23
- static getIndex(array: any[], propertyName: string, value: any) {
24
- for (let i = 0; i < array.length; i++) {
25
- const item = array[i];
26
- if (ArrayHelper.compare(item, propertyName, value)) return i;
27
- }
28
- return -1;
29
- }
30
-
31
- static getOne(array: any[], propertyName: string, value: any) {
32
- for (const item of array || []) if (ArrayHelper.compare(item, propertyName, value)) return item;
33
- return null
34
- }
35
-
36
- static getAll(array: any[], propertyName: string, value: any) {
37
- const result: any[] = []
38
- for (const item of array || []) {
39
- if (ArrayHelper.compare(item, propertyName, value)) result.push(item);
40
- }
41
- return result;
42
- }
43
-
44
- static getAllArray(array: any[], propertyName: string, values: any[]) {
45
- const result: any[] = []
46
- for (const item of array || []) if (values.indexOf(item[propertyName]) > -1) result.push(item);
47
- return result;
48
- }
49
-
50
- static getAllContaining(array: any[], propertyName: string, value: any) {
51
- const result: any[] = []
52
- for (const item of array) if (item[propertyName].toString().toLowerCase().indexOf(value.toLowerCase()) > -1) result.push(item);
53
- return result;
54
- }
55
-
56
- private static compare(item: any, propertyName: string, value: any) {
57
- const propChain = propertyName.split(".");
58
- if (propChain.length === 1) return item[propertyName] === value;
59
- else {
60
- let obj = item;
61
- for (let i = 0; i < propChain.length - 1; i++) {
62
- if (obj) obj = obj[propChain[i]];
63
- }
64
- return obj[propChain[propChain.length - 1]] === value;
65
- }
66
- }
67
-
68
- static getUniqueValues(array: any[], propertyName: string) {
69
- const result: any[] = [];
70
-
71
- for (const item of array) {
72
- const val = (propertyName.indexOf(".") === -1) ? item[propertyName] : this.getDeepValue(item, propertyName)
73
- if (result.indexOf(val) === -1) result.push(val);
74
- }
75
- return result;
76
- }
77
-
78
- static getDeepValue(item: any, propertyName: string) {
79
- const propertyNames = propertyName.split(".");
80
- let result: any = item;
81
- propertyNames.forEach(name => {
82
- result = result[name];
83
- });
84
- return result;
85
- }
86
-
87
- }
1
+ import { UniqueIdHelper } from "./UniqueIdHelper";
2
+
3
+ export class ArrayHelper {
4
+
5
+ static getIds(array: any[], propertyName: string) {
6
+ const result: string[] = [];
7
+ for (const item of array) {
8
+ const id = item[propertyName]?.toString();
9
+ if (!UniqueIdHelper.isMissing(id) && result.indexOf(id) === -1) result.push(id);
10
+ }
11
+ return result;
12
+ }
13
+
14
+ static sortBy(array: any[], propertyName: string, descending: boolean = false) {
15
+ array.sort((a, b) => {
16
+ const valA = a[propertyName];
17
+ const valB = b[propertyName];
18
+ if (valA < valB) return descending ? 1 : -1;
19
+ else return descending ? -1 : 1;
20
+ });
21
+ }
22
+
23
+ static getIndex(array: any[], propertyName: string, value: any) {
24
+ for (let i = 0; i < array.length; i++) {
25
+ const item = array[i];
26
+ if (ArrayHelper.compare(item, propertyName, value)) return i;
27
+ }
28
+ return -1;
29
+ }
30
+
31
+ static getOne(array: any[], propertyName: string, value: any) {
32
+ for (const item of array || []) if (ArrayHelper.compare(item, propertyName, value)) return item;
33
+ return null
34
+ }
35
+
36
+ static getAll(array: any[], propertyName: string, value: any) {
37
+ const result: any[] = []
38
+ for (const item of array || []) {
39
+ if (ArrayHelper.compare(item, propertyName, value)) result.push(item);
40
+ }
41
+ return result;
42
+ }
43
+
44
+ static getAllArray(array: any[], propertyName: string, values: any[]) {
45
+ const result: any[] = []
46
+ for (const item of array || []) if (values.indexOf(item[propertyName]) > -1) result.push(item);
47
+ return result;
48
+ }
49
+
50
+ static getAllContaining(array: any[], propertyName: string, value: any) {
51
+ const result: any[] = []
52
+ for (const item of array) if (item[propertyName].toString().toLowerCase().indexOf(value.toLowerCase()) > -1) result.push(item);
53
+ return result;
54
+ }
55
+
56
+ private static compare(item: any, propertyName: string, value: any) {
57
+ const propChain = propertyName.split(".");
58
+ if (propChain.length === 1) return item[propertyName] === value;
59
+ else {
60
+ let obj = item;
61
+ for (let i = 0; i < propChain.length - 1; i++) {
62
+ if (obj) obj = obj[propChain[i]];
63
+ }
64
+ return obj[propChain[propChain.length - 1]] === value;
65
+ }
66
+ }
67
+
68
+ static getUniqueValues(array: any[], propertyName: string) {
69
+ const result: any[] = [];
70
+
71
+ for (const item of array) {
72
+ const val = (propertyName.indexOf(".") === -1) ? item[propertyName] : this.getDeepValue(item, propertyName)
73
+ if (result.indexOf(val) === -1) result.push(val);
74
+ }
75
+ return result;
76
+ }
77
+
78
+ static getDeepValue(item: any, propertyName: string) {
79
+ const propertyNames = propertyName.split(".");
80
+ let result: any = item;
81
+ propertyNames.forEach(name => {
82
+ result = result[name];
83
+ });
84
+ return result;
85
+ }
86
+
87
+ }
@@ -1,10 +1,10 @@
1
- export class CurrencyHelper {
2
- static formatCurrency(amount: number) {
3
- const formatter = new Intl.NumberFormat("en-US", {
4
- style: "currency",
5
- currency: "USD",
6
- minimumFractionDigits: 2
7
- });
8
- return formatter.format(amount);
9
- }
10
- }
1
+ export class CurrencyHelper {
2
+ static formatCurrency(amount: number) {
3
+ const formatter = new Intl.NumberFormat("en-US", {
4
+ style: "currency",
5
+ currency: "USD",
6
+ minimumFractionDigits: 2
7
+ });
8
+ return formatter.format(amount);
9
+ }
10
+ }
@@ -1,104 +1,104 @@
1
- import { format as dateFormat } from "date-fns"
2
-
3
- export class DateHelper {
4
-
5
- //Fixes timezone issues when you just need the date.
6
- static toDate(input: any) {
7
- return new Date(Date.parse(input.toString().replace("Z", "")));
8
- }
9
-
10
- static toDateTime(input: any) {
11
- return new Date(Date.parse(input.toString()));
12
- }
13
-
14
- static addDays(date: Date, days: number) {
15
- date.setDate(date.getDate() + days);
16
- return date;
17
- }
18
-
19
- static prettyDate(date: Date) {
20
- if (date === undefined || date === null) return "";
21
- return this.formatDateTime(date, "MMM d, yyyy");
22
- }
23
-
24
- static prettyDateTime(date: Date) {
25
- if (date === undefined || date === null) return "";
26
- return this.formatDateTime(date, "MMM d, yyyy h:mm a");
27
- }
28
-
29
- static prettyTime(date: Date) {
30
- if (date === undefined || date === null) return "";
31
- return this.formatDateTime(date, "h:mm a");
32
- }
33
-
34
- static getLastSunday() {
35
- let result = new Date();
36
- while (result.getDay() !== 0) result.setDate(result.getDate() - 1);
37
- return result;
38
- }
39
-
40
- static getWeekSunday(year: number, week: number) {
41
- let result = new Date(year, 0, 1);
42
- while (result.getDay() !== 0) result.setDate(result.getDate() + 1);
43
- result.setDate(result.getDate() + ((week - 1) * 7));
44
- return result;
45
- }
46
-
47
- static formatHtml5Date(date: Date): string {
48
- let result = "";
49
- if (date !== undefined && date !== null) {
50
- try {
51
- result = new Date(date).toISOString().split("T")[0];
52
- } catch { }
53
- }
54
- return result;
55
- }
56
-
57
- static formatHtml5Time(time: Date): string {
58
- let h = time.getHours();
59
- let m = time.getMinutes();
60
- let s = time.getSeconds();
61
- return `${h < 10 ? ("0" + h) : h}:${m < 10 ? ("0" + m) : m}:${s < 10 ? ("0" + s) : s}`;
62
- }
63
-
64
- static formatHtml5DateTime(date: Date): string {
65
- if (date === undefined || date === null) return "";
66
- else {
67
- return this.formatDateTime(date, "yyyy-MM-dd") + "T" + this.formatDateTime(date, "HH:mm");
68
- }
69
- }
70
-
71
- static getDisplayDuration(d: Date): string {
72
- let seconds = Math.round((new Date().getTime() - d.getTime()) / 1000);
73
- if (seconds > 86400) {
74
- let days = Math.floor(seconds / 86400);
75
- return (days === 1) ? "1d" : days.toString() + "d";
76
- }
77
- else if (seconds > 3600) {
78
- let hours = Math.floor(seconds / 3600);
79
- return (hours === 1) ? "1h" : hours.toString() + "h";
80
- }
81
- else if (seconds > 60) {
82
- let minutes = Math.floor(seconds / 60);
83
- return (minutes === 1) ? "1m" : minutes.toString() + "m";
84
- }
85
- else if (seconds < 1) return "now";
86
- else return (seconds === 1) ? "1s" : Math.floor(seconds).toString() + "s";
87
- }
88
-
89
- static getShortDate(d: Date): string {
90
- return (d.getMonth() + 1).toString() + "/" + (d.getDate()).toString() + "/" + d.getFullYear().toString();
91
- }
92
-
93
- static convertDatePickerFormat(d: Date): Date {
94
- const date = this.formatHtml5Date(d).split("-");
95
- if (date.length === 3) return new Date(`${date[1]}-${date[2]}-${date[0]}`);
96
- return new Date();
97
- }
98
-
99
- private static formatDateTime(date: Date, format: string) {
100
- try {
101
- return dateFormat(date, format);
102
- } catch { return ""; }
103
- }
104
- }
1
+ import { format as dateFormat } from "date-fns"
2
+
3
+ export class DateHelper {
4
+
5
+ //Fixes timezone issues when you just need the date.
6
+ static toDate(input: any) {
7
+ return new Date(Date.parse(input.toString().replace("Z", "")));
8
+ }
9
+
10
+ static toDateTime(input: any) {
11
+ return new Date(Date.parse(input.toString()));
12
+ }
13
+
14
+ static addDays(date: Date, days: number) {
15
+ date.setDate(date.getDate() + days);
16
+ return date;
17
+ }
18
+
19
+ static prettyDate(date: Date) {
20
+ if (date === undefined || date === null) return "";
21
+ return this.formatDateTime(date, "MMM d, yyyy");
22
+ }
23
+
24
+ static prettyDateTime(date: Date) {
25
+ if (date === undefined || date === null) return "";
26
+ return this.formatDateTime(date, "MMM d, yyyy h:mm a");
27
+ }
28
+
29
+ static prettyTime(date: Date) {
30
+ if (date === undefined || date === null) return "";
31
+ return this.formatDateTime(date, "h:mm a");
32
+ }
33
+
34
+ static getLastSunday() {
35
+ let result = new Date();
36
+ while (result.getDay() !== 0) result.setDate(result.getDate() - 1);
37
+ return result;
38
+ }
39
+
40
+ static getWeekSunday(year: number, week: number) {
41
+ let result = new Date(year, 0, 1);
42
+ while (result.getDay() !== 0) result.setDate(result.getDate() + 1);
43
+ result.setDate(result.getDate() + ((week - 1) * 7));
44
+ return result;
45
+ }
46
+
47
+ static formatHtml5Date(date: Date): string {
48
+ let result = "";
49
+ if (date !== undefined && date !== null) {
50
+ try {
51
+ result = new Date(date).toISOString().split("T")[0];
52
+ } catch { }
53
+ }
54
+ return result;
55
+ }
56
+
57
+ static formatHtml5Time(time: Date): string {
58
+ let h = time.getHours();
59
+ let m = time.getMinutes();
60
+ let s = time.getSeconds();
61
+ return `${h < 10 ? ("0" + h) : h}:${m < 10 ? ("0" + m) : m}:${s < 10 ? ("0" + s) : s}`;
62
+ }
63
+
64
+ static formatHtml5DateTime(date: Date): string {
65
+ if (date === undefined || date === null) return "";
66
+ else {
67
+ return this.formatDateTime(date, "yyyy-MM-dd") + "T" + this.formatDateTime(date, "HH:mm");
68
+ }
69
+ }
70
+
71
+ static getDisplayDuration(d: Date): string {
72
+ let seconds = Math.round((new Date().getTime() - d.getTime()) / 1000);
73
+ if (seconds > 86400) {
74
+ let days = Math.floor(seconds / 86400);
75
+ return (days === 1) ? "1d" : days.toString() + "d";
76
+ }
77
+ else if (seconds > 3600) {
78
+ let hours = Math.floor(seconds / 3600);
79
+ return (hours === 1) ? "1h" : hours.toString() + "h";
80
+ }
81
+ else if (seconds > 60) {
82
+ let minutes = Math.floor(seconds / 60);
83
+ return (minutes === 1) ? "1m" : minutes.toString() + "m";
84
+ }
85
+ else if (seconds < 1) return "now";
86
+ else return (seconds === 1) ? "1s" : Math.floor(seconds).toString() + "s";
87
+ }
88
+
89
+ static getShortDate(d: Date): string {
90
+ return (d.getMonth() + 1).toString() + "/" + (d.getDate()).toString() + "/" + d.getFullYear().toString();
91
+ }
92
+
93
+ static convertDatePickerFormat(d: Date): Date {
94
+ const date = this.formatHtml5Date(d).split("-");
95
+ if (date.length === 3) return new Date(`${date[1]}-${date[2]}-${date[0]}`);
96
+ return new Date();
97
+ }
98
+
99
+ private static formatDateTime(date: Date, format: string) {
100
+ try {
101
+ return dateFormat(date, format);
102
+ } catch { return ""; }
103
+ }
104
+ }