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/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
- * Kiểm tra xem URL git có hợp lệ hay không (HTTP/HTTPS, SSH, hoặc `.git`)
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 chuỗi thời gian thành định dạng ISO/Git hợp lệ.
21
- * Hỗ trợ các định dạng:
22
- * - "now" hoặc để trống -> Thời gian hiện tại
23
- * - Relative (phân biệt hoa/thường cho đơn vị 1 ký tự):
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
- * VD: "-2d", "-5h", "-30m" (phút), "-1w", "-3M"/"-3mo"/"-3month" (tháng), "-1y"
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
- // Kiểm tra relative time: ví dụ -2d, -5h, -30m, -1w, -3M/-3mo, -1y hoặc 2d, 5h
44
- // Lưu ý: đơn vị 1 ký tự phân biệt hoa/thường (m = minute, M = month).
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
- // Map unit: ưu tiên so khớp từ dài trước, đơn vị 1 ký tự giữ case-sensitive
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
- // Nếu người dùng nhập "2d" mà không có dấu "-", mặc định hiểu là "lùi 2d" (-2d)
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: `Không thể tính toán thời gian từ '${dateStr}'` };
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
- // Rơi xuống parse absolute nếu unit không khớp (vd user gõ nhầm sẽ báo lỗi ở dưới)
85
+ // Fall through to absolute date parsing if the unit is unknown.
86
86
  }
87
87
 
88
- // Thủ định dạng ngày giờ tuyệt đối
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); // Thử parse chuẩn ISO
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: `Định dạng ngày giờ không hợp lệ: '${dateStr}'. Ví dụ đúng: "2024-01-15 14:30:00", "-2d", "-5h", "now"`
118
+ error: `Invalid date or time: '${dateStr}'. Examples: "2024-01-15 14:30:00", "-2d", "-5h", "now"`
119
119
  };
120
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-push-time",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "CLI tool to push project to Git with custom repo URL and custom commit timestamp",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",