git-push-time 1.1.3 → 1.1.4
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.
- package/README.md +109 -111
- package/bin/index.js +45 -46
- package/lib/commands/edit-time.js +27 -27
- package/lib/commands/fix.js +19 -19
- package/lib/commands/github.js +98 -98
- package/lib/commands/pull.js +13 -13
- package/lib/commands/push.js +147 -147
- package/lib/config.js +17 -17
- package/lib/fix.js +34 -34
- package/lib/git.js +88 -88
- package/lib/github.js +39 -39
- package/lib/prompt-helpers.js +19 -20
- package/lib/secrets.js +12 -12
- package/lib/ui.js +122 -125
- package/lib/utils.js +15 -15
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
|
4
4
|
dayjs.extend(customParseFormat);
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Check whether a Git URL is valid (HTTP/HTTPS, SSH, or `.git`).
|
|
8
8
|
* @param {string} url
|
|
9
9
|
* @returns {boolean}
|
|
10
10
|
*/
|
|
@@ -17,12 +17,12 @@ export function isValidGitUrl(url) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Parse
|
|
21
|
-
*
|
|
22
|
-
* - "now"
|
|
23
|
-
* - Relative (
|
|
20
|
+
* Parse a date string into a valid ISO/Git timestamp.
|
|
21
|
+
* Supported formats:
|
|
22
|
+
* - "now" or blank -> current time
|
|
23
|
+
* - Relative times (single-character units are case-sensitive):
|
|
24
24
|
* s=second, m=minute, h=hour, d=day, w=week, M=month, y=year
|
|
25
|
-
*
|
|
25
|
+
* e.g. "-2d", "-5h", "-30m" (minutes), "-1w", "-3M"/"-3mo"/"-3month" (months), "-1y"
|
|
26
26
|
* - Absolute: "YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm", "YYYY-MM-DD"
|
|
27
27
|
*
|
|
28
28
|
* @param {string} dateStr
|
|
@@ -40,15 +40,15 @@ export function parseCustomDate(dateStr) {
|
|
|
40
40
|
|
|
41
41
|
const str = dateStr.trim();
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
//
|
|
43
|
+
// Check relative time: e.g. -2d, -5h, -30m, -1w, -3M/-3mo, -1y, or 2d, 5h.
|
|
44
|
+
// Single-character units are case-sensitive (m = minute, M = month).
|
|
45
45
|
const relativeMatch = str.match(/^([+-]?\d+)\s*(\S+)$/);
|
|
46
46
|
if (relativeMatch) {
|
|
47
47
|
let amount = parseInt(relativeMatch[1], 10);
|
|
48
48
|
const unitRaw = relativeMatch[2];
|
|
49
49
|
const unitLower = unitRaw.toLowerCase();
|
|
50
50
|
|
|
51
|
-
//
|
|
51
|
+
// Match longer units first; preserve case for single-character units.
|
|
52
52
|
let unit = null;
|
|
53
53
|
if (['sec', 'secs', 'second', 'seconds'].includes(unitLower)) unit = 'second';
|
|
54
54
|
else if (['min', 'mins', 'minute', 'minutes'].includes(unitLower)) unit = 'minute';
|
|
@@ -66,14 +66,14 @@ export function parseCustomDate(dateStr) {
|
|
|
66
66
|
else if (unitRaw === 'y' || unitRaw === 'Y') unit = 'year';
|
|
67
67
|
|
|
68
68
|
if (unit) {
|
|
69
|
-
//
|
|
69
|
+
// Without a leading + or -, interpret "2d" as "2 days ago" (-2d).
|
|
70
70
|
if (amount > 0 && !str.startsWith('+')) {
|
|
71
71
|
amount = -amount;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const calculated = dayjs().add(amount, unit);
|
|
75
75
|
if (!calculated.isValid()) {
|
|
76
|
-
return { valid: false, formatted: '', display: '', error: `
|
|
76
|
+
return { valid: false, formatted: '', display: '', error: `Could not calculate a date from '${dateStr}'` };
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
return {
|
|
@@ -82,10 +82,10 @@ export function parseCustomDate(dateStr) {
|
|
|
82
82
|
display: calculated.format('YYYY-MM-DD HH:mm:ss Z')
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
//
|
|
85
|
+
// Fall through to absolute date parsing if the unit is unknown.
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// Try absolute date and time formats.
|
|
89
89
|
const formats = [
|
|
90
90
|
'YYYY-MM-DD HH:mm:ss',
|
|
91
91
|
'YYYY-MM-DD HH:mm',
|
|
@@ -100,7 +100,7 @@ export function parseCustomDate(dateStr) {
|
|
|
100
100
|
|
|
101
101
|
let parsed = dayjs(str, formats, true);
|
|
102
102
|
if (!parsed.isValid()) {
|
|
103
|
-
parsed = dayjs(str); //
|
|
103
|
+
parsed = dayjs(str); // Try standard ISO parsing.
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (parsed.isValid()) {
|
|
@@ -115,6 +115,6 @@ export function parseCustomDate(dateStr) {
|
|
|
115
115
|
valid: false,
|
|
116
116
|
formatted: '',
|
|
117
117
|
display: '',
|
|
118
|
-
error:
|
|
118
|
+
error: `Invalid date or time: '${dateStr}'. Examples: "2024-01-15 14:30:00", "-2d", "-5h", "now"`
|
|
119
119
|
};
|
|
120
120
|
}
|