@stacksjs/git 0.58.47 → 0.58.49

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 +4 -3
  2. package/src/index.ts +63 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/git",
3
3
  "type": "module",
4
- "version": "0.58.47",
4
+ "version": "0.58.49",
5
5
  "description": "The Stacks git utilities & conventions.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
@@ -39,7 +39,8 @@
39
39
  ],
40
40
  "files": [
41
41
  "README.md",
42
- "dist"
42
+ "dist",
43
+ "src"
43
44
  ],
44
45
  "scripts": {
45
46
  "build": "bun --bun build.ts",
@@ -63,6 +64,6 @@
63
64
  "simple-git-hooks": "^2.9.0"
64
65
  },
65
66
  "devDependencies": {
66
- "@stacksjs/development": "workspace:*"
67
+ "@stacksjs/development": "latest"
67
68
  }
68
69
  }
package/src/index.ts ADDED
@@ -0,0 +1,63 @@
1
+ export * as changelog from 'changelogen'
2
+
3
+ export function useGitHub() {
4
+ function getTimeDifference(givenDateString: string): string {
5
+ // Convert the given date string to a Date object
6
+ const givenDate: Date = new Date(givenDateString)
7
+
8
+ // Get the current date and time
9
+ const currentDate: Date = new Date()
10
+
11
+ // Calculate the time difference in milliseconds
12
+ const timeDifference: number = currentDate.getTime() - givenDate.getTime()
13
+
14
+ // Calculate the difference in seconds, minutes, hours, and days
15
+ const secondsDifference: number = Math.floor(timeDifference / 1000)
16
+ const minutesDifference: number = Math.floor(secondsDifference / 60)
17
+ const hoursDifference: number = Math.floor(minutesDifference / 60)
18
+ const daysDifference: number = Math.floor(hoursDifference / 24)
19
+ const weeksDifference: number = Math.floor(daysDifference / 7)
20
+
21
+ if (secondsDifference < 60) {
22
+ // If less than 60 seconds, return seconds only
23
+ return `${secondsDifference}s`
24
+ }
25
+ else if (minutesDifference < 60) {
26
+ // If less than 60 minutes, return minutes and remaining seconds
27
+ const remainingSeconds = secondsDifference % 60
28
+ return `${minutesDifference}m ${remainingSeconds}s`
29
+ }
30
+ else if (hoursDifference < 24) {
31
+ // If less than 24 hours, return hours and remaining minutes
32
+ const remainingMinutes = minutesDifference % 60
33
+ return `${hoursDifference}h ${remainingMinutes}m`
34
+ }
35
+ else if (weeksDifference < 7) {
36
+ const remainingHours: number = hoursDifference % 24
37
+
38
+ return `${daysDifference}d ${remainingHours}h`
39
+ }
40
+
41
+ return `${weeksDifference}w`
42
+ }
43
+
44
+ function formatDuration(durationInSeconds: number): string {
45
+ const minutes = Math.floor(durationInSeconds / 60)
46
+ const seconds = durationInSeconds % 60
47
+
48
+ if (minutes > 1)
49
+ return `${minutes}m ${seconds}s`
50
+
51
+ return `${seconds}s`
52
+ }
53
+
54
+ function getActionRunDuration(startTime: Date, endTime: Date): string {
55
+ const start = new Date(startTime)
56
+ const end = new Date(endTime)
57
+ const durationInSeconds = Math.floor((end.getTime() - start.getTime()) / 1000)
58
+
59
+ return formatDuration(durationInSeconds)
60
+ }
61
+
62
+ return { getTimeDifference, formatDuration, getActionRunDuration }
63
+ }