| @@ -2,8 +2,12 @@ | ||
| 2 | 2 | import { |
| 3 | 3 | applyCurrencyPosition, |
| 4 | 4 | formatYatraMoney, |
| 5 | 5 | } from "../../lib/currency-display"; |
| 6 | +import { | |
| 7 | + formatDate as formatGlobalDate, | |
| 8 | + parseDate, | |
| 9 | +} from "../../lib/dateFormat"; | |
| 6 | 10 | |
| 7 | 11 | function toBrowserLocaleTag( |
| 8 | 12 | locale: string | undefined | null, |
| 9 | 13 | ): string | undefined { |
| @@ -24,24 +28,17 @@ | ||
| 24 | 28 | if (!value) { |
| 25 | 29 | return __("N/A", "yatra"); |
| 26 | 30 | } |
| 27 | 31 | |
| 28 | - try { | |
| 29 | - const date = new Date(value); | |
| 30 | - | |
| 31 | - // Check if date is valid | |
| 32 | - if (isNaN(date.getTime())) { | |
| 33 | - return __("Invalid date", "yatra"); | |
| 34 | - } | |
| 35 | - | |
| 36 | - return date.toLocaleDateString(getAccountLocale(), { | |
| 37 | - year: "numeric", | |
| 38 | - month: "long", | |
| 39 | - day: "numeric", | |
| 40 | - }); | |
| 41 | - } catch (error) { | |
| 32 | + // Render public account dates in the operator's configured global date | |
| 33 | + // format (Settings → General) via the shared formatter — not a hardcoded | |
| 34 | + // browser style. It also parses a date-only value (e.g. a booking's | |
| 35 | + // travel_date) in LOCAL time, so it no longer rolls back a day in behind-UTC | |
| 36 | + // timezones (Aug 1 → Jul 31). | |
| 37 | + if (!parseDate(value)) { | |
| 42 | 38 | return __("Invalid date", "yatra"); |
| 43 | 39 | } |
| 40 | + return formatGlobalDate(value); | |
| 44 | 41 | }; |
| 45 | 42 | |
| 46 | 43 | /** Leading Y-m-d from API datetime strings for stable range comparison. */ |
| 47 | 44 | function extractYmd(value: string | undefined | null): string | null { |