(dateStr: string | undefined)
| 162 | * @returns Git-compatible date string or undefined |
| 163 | */ |
| 164 | export function toGitDate(dateStr: string | undefined): string | undefined { |
| 165 | if (!dateStr) { |
| 166 | return undefined; |
| 167 | } |
| 168 | |
| 169 | // Git natively understands these formats, so preserve them |
| 170 | const gitNativeFormats = [ |
| 171 | /^\d+\s+(second|minute|hour|day|week|month|year)s?\s+ago$/i, |
| 172 | /^yesterday$/i, |
| 173 | /^last\s+(week|month|year)$/i, |
| 174 | /^\d{4}-\d{2}-\d{2}$/, // ISO date |
| 175 | /^\d{4}-\d{2}-\d{2}T/, // ISO datetime |
| 176 | ]; |
| 177 | |
| 178 | for (const pattern of gitNativeFormats) { |
| 179 | if (pattern.test(dateStr)) { |
| 180 | return dateStr; // Git can handle this directly |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // Otherwise, parse and convert to ISO |
| 185 | return parseTemporalDate(dateStr); |
| 186 | } |
no test coverage detected