@churchapps/helpers 1.0.1 → 1.0.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 (2) hide show
  1. package/package.json +2 -1
  2. package/src/DateHelper.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchapps/helpers",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Library of helper functions not specific to any one ChurchApps project or framework.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "axios": "^1.5.0",
33
33
  "date-fns": "^2.30.0",
34
+ "dayjs": "^1.11.9",
34
35
  "react-ga4": "^2.1.0",
35
36
  "rrule": "^2.7.2"
36
37
  }
package/src/DateHelper.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { format as dateFormat } from "date-fns"
2
+ import dayjs from "dayjs"
2
3
 
3
4
  export class DateHelper {
4
5
 
@@ -105,4 +106,17 @@ export class DateHelper {
105
106
  return dateFormat(date, format);
106
107
  } catch { return ""; }
107
108
  }
109
+
110
+ public static toMysqlDate(d: Date) {
111
+ if (d === null || d === undefined) {
112
+ return undefined;
113
+ }
114
+ return dayjs(d).format("YYYY-MM-DD HH:mm:ss")
115
+ }
116
+
117
+ public static subtractHoursFromNow(hour: number) {
118
+ const now = new Date();
119
+ return new Date(now.setHours(now.getHours() - hour));
120
+ }
121
+
108
122
  }