-
-
Notifications
You must be signed in to change notification settings - Fork 37
Dates in financial documents should be absolute or explicitly timezoned. #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
360d18d
354a576
5647317
4491c46
52c7766
9b9c74e
c26f62f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * Returns the user's local UTC offset string, e.g. "UTC+5:30" or "UTC-8:00" | ||
| */ | ||
| function getUTCOffset() { | ||
| const offset = -new Date().getTimezoneOffset(); // minutes, sign flipped | ||
| const sign = offset >= 0 ? "+" : "-"; | ||
| const abs = Math.abs(offset); | ||
| const hours = Math.floor(abs / 60); | ||
| const minutes = abs % 60; | ||
| return `UTC${sign}${hours}:${minutes.toString().padStart(2, "0")}`; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Formats invoice issue/due dates (date only, no time). | ||
| * Output: "Feb 20, 2026 (UTC+5:30)" | ||
| * | ||
| * Why: new Date(isoString).toLocaleDateString() silently shifts the date | ||
| * across midnight for users in negative UTC offsets. Rendering the calendar | ||
| * date only keeps financial document dates stable across viewers. | ||
| * | ||
| * @param {string|Date} dateStr | ||
| * @returns {string} | ||
| + */ | ||
| export function formatInvoiceDate(dateStr) { | ||
| if (!dateStr) return "N/A"; | ||
| // Strip time component to avoid UTC→local midnight shift | ||
| // "2026-02-20T..." or "2026-02-20" → ["2026","02","20"] | ||
| const parts = String(dateStr).split("T")[0].split("-"); | ||
| if (parts.length === 3) { | ||
| const [year, month, day] = parts.map(Number); | ||
| const date = new Date(year, month - 1, day); // local date, no TZ conversion | ||
| if (isNaN(date.getTime())) return "Invalid date"; | ||
| return date.toLocaleDateString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "numeric", | ||
| }); | ||
| } | ||
| // Fallback for non-ISO formats | ||
| const date = new Date(dateStr); | ||
| if (isNaN(date.getTime())) return "Invalid date"; | ||
| return date.toLocaleDateString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "numeric", | ||
| }); | ||
|
|
||
|
Comment on lines
+13
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
sed -n '1,80p' frontend/src/utils/formatDate.js
rg -n 'formatInvoiceDate|formatDateTime' frontend/src/utils/formatDate.js frontend/src/page/SentInvoice.jsx frontend/src/page/BatchPayment.jsxRepository: StabilityNexus/Chainvoice Length of output: 3122 🏁 Script executed: #!/bin/bash
# Get full file to see if formatInvoiceDate exists
wc -l frontend/src/utils/formatDate.js
echo "---"
# Show entire file with line numbers
cat -n frontend/src/utils/formatDate.js
echo "---"
# Check for export statements
rg -n 'export' frontend/src/utils/formatDate.jsRepository: StabilityNexus/Chainvoice Length of output: 2656 Wrap and export Lines 24–44 lack the function wrapper and export statement. The code executes immediately when the module loads, attempting to access undefined 🛠️ Proposed fix /**
* Formats invoice issue/due dates (date only, no time).
- * Output: "Feb 20, 2026 (UTC+5:30)"
+ * Output: "Feb 20, 2026"
*
* Why: new Date(isoString).toLocaleDateString() silently shifts the date
- * across midnight for users in negative UTC offsets. Showing the offset
- * makes the displayed date unambiguous for financial documents.
+ * across midnight for users in negative UTC offsets. Rendering the calendar
+ * date only keeps financial document dates stable across viewers.
*
* `@param` {string|Date} dateStr
* `@returns` {string}
-*/
- // Strip time component to avoid UTC→local midnight shift.
+ */
+export function formatInvoiceDate(dateStr) {
+ if (!dateStr) return "N/A";
+ // Strip time component to avoid UTC→local midnight shift.
// "2026-02-20T..." or "2026-02-20" → ["2026","02","20"]
- const parts = dateStr.split("T")[0].split("-");
+ const parts = String(dateStr).split("T")[0].split("-");
if (parts.length === 3) {
const [year, month, day] = parts.map(Number);
const date = new Date(year, month - 1, day); // local date, no TZ conversion
if (isNaN(date.getTime())) return "Invalid date";
return date.toLocaleDateString("en-US", {
@@
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
+}🤖 Prompt for AI Agents |
||
| /** | ||
| * Formats a full timestamp (date + time) for table rows. | ||
| * * Output: "Feb 20, 2026" | ||
| * | ||
| * @param {string|Date} dateStr | ||
| * @returns {string} | ||
| */ | ||
| export function formatDateTime(dateStr) { | ||
| if (!dateStr) return "N/A"; | ||
| const date = new Date(dateStr); | ||
| if (isNaN(date.getTime())) return "Invalid date"; | ||
| const formatted = date.toLocaleString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "numeric", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| }); | ||
| return `${formatted} (${getUTCOffset()})`; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 221
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 2112
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 510
🏁 Script executed:
rg -n 'getUTCOffset' -t js -t jsx -t ts -t tsxRepository: StabilityNexus/Chainvoice
Length of output: 96
🏁 Script executed:
rg -n 'getUTCOffset'Repository: StabilityNexus/Chainvoice
Length of output: 210
Pass the parsed
datetogetUTCOffset()to ensure the UTC label matches the timestamp's timezone.getUTCOffset()currently reads the current clock. If a winter timestamp is displayed during DST, the appended UTC label can differ by an hour from the offset used bydate.toLocaleString(), creating inconsistency. The parseddatevariable is already available informatDateTime()on line 59—pass it to the function so the label matches the timestamp being shown.Proposed fix
🤖 Prompt for AI Agents