diff --git a/config/requestTypeFields.json b/config/requestTypeFields.json index ce87d91..0f3b083 100644 --- a/config/requestTypeFields.json +++ b/config/requestTypeFields.json @@ -16,9 +16,7 @@ "common": { "displayFields": [ { "path": "transition.transitionName", "label": "Approval step" }, - { "path": "transition.from_status", "label": "From status" }, - { "path": "transition.to_status", "label": "To status" }, - { "path": "user.displayName", "label": "Moved by" }, + { "path": "transition.to_status", "label": "Status" }, { "fieldId": "priority", "label": "Priority", "format": "option" }, { "fieldId": "assignee", "label": "Assignee", "format": "user" }, { "fieldId": "created", "label": "Created", "format": "datetime" }, diff --git a/lib/requestTypeFields.js b/lib/requestTypeFields.js index 4eef13d..47d8c73 100644 --- a/lib/requestTypeFields.js +++ b/lib/requestTypeFields.js @@ -2,6 +2,46 @@ import fs from 'fs'; import { formatJiraRichText } from './jiraRichText.js'; const SKIP_FIELD_IDS = new Set(['attachment']); +const EASTERN_TIME_ZONE = 'America/New_York'; + +export function formatEasternDateTime(value) { + const date = new Date(value); + if (Number.isNaN(date.getTime())) { + return String(value); + } + + const formatted = new Intl.DateTimeFormat('en-US', { + timeZone: EASTERN_TIME_ZONE, + month: 'numeric', + day: 'numeric', + year: 'numeric', + hour: 'numeric', + minute: '2-digit', + second: '2-digit', + hour12: true, + }).format(date); + + const timeZoneName = new Intl.DateTimeFormat('en-US', { + timeZone: EASTERN_TIME_ZONE, + timeZoneName: 'short', + }).formatToParts(date).find(part => part.type === 'timeZoneName')?.value || 'ET'; + + return `${formatted} ${timeZoneName}`; +} + +export function formatEasternDate(value) { + const date = new Date(value); + if (Number.isNaN(date.getTime())) { + return String(value); + } + + return new Intl.DateTimeFormat('en-US', { + timeZone: EASTERN_TIME_ZONE, + month: 'numeric', + day: 'numeric', + year: 'numeric', + }).format(date); +} export function loadRequestTypeFields() { const path = './config/requestTypeFields.json'; @@ -68,8 +108,9 @@ export function formatFieldValue(value, format) { } return value.map(item => formatFieldValue(item, 'user')).filter(Boolean).join(', '); case 'datetime': + return formatEasternDateTime(value); case 'date': - return new Date(value).toLocaleString(); + return formatEasternDate(value); case 'cmdb': if (Array.isArray(value)) { return value.map(item => item.label || item.name || item.objectKey || item.value).filter(Boolean).join(', '); diff --git a/services/approvalCards.js b/services/approvalCards.js index 2f805b6..17dce11 100644 --- a/services/approvalCards.js +++ b/services/approvalCards.js @@ -1,4 +1,4 @@ -import { buildDetailLinesForRequestType } from '../lib/requestTypeFields.js'; +import { buildDetailLinesForRequestType, formatEasternDateTime } from '../lib/requestTypeFields.js'; const PORTAL_BASE_URL = 'https://aeo.atlassian.net/servicedesk/customer/portal/135'; @@ -152,13 +152,10 @@ function buildFallbackChangeDetailLines(jiraTicket) { lines.push({ label: 'Business justification', value: fields.customfield_10252 }); } if (fields.customfield_10257) { - const changeDate = new Date(fields.customfield_10257).toLocaleDateString(); - const changeTime = new Date(fields.customfield_10257).toLocaleTimeString([], { - hour: '2-digit', - minute: '2-digit', - hour12: true, + lines.push({ + label: 'Implementation date', + value: formatEasternDateTime(fields.customfield_10257), }); - lines.push({ label: 'Implementation date', value: `${changeDate} ${changeTime}` }); } return lines; diff --git a/test/requestTypeFields.test.js b/test/requestTypeFields.test.js index f64cfaf..cfd5e72 100644 --- a/test/requestTypeFields.test.js +++ b/test/requestTypeFields.test.js @@ -2,6 +2,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { buildDetailLinesForRequestType, + formatEasternDateTime, formatFieldValue, getDisplayFieldsForRequestType, } from '../lib/requestTypeFields.js'; @@ -72,6 +73,13 @@ describe('formatFieldValue', () => { 'Store 123, Store 456' ); }); + + it('formats datetimes in Eastern time', () => { + const formatted = formatFieldValue('2026-07-28T20:33:16.000Z', 'datetime'); + assert.match(formatted, /EDT|EST/); + assert.match(formatted, /7\/28\/2026/); + assert.doesNotMatch(formatted, /20:33:16/); + }); }); describe('buildDetailLinesForRequestType', () => {