-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7372 from uktrade/bugfix/export-win-dates
Fix export win dates
- Loading branch information
Showing
11 changed files
with
429 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
formatDate, | ||
DATE_FORMAT_FULL, | ||
DATE_FORMAT_FULL_DAY, | ||
DATE_FORMAT_COMPACT, | ||
DATE_FORMAT_ISO, | ||
DATE_FORMAT_MEDIUM, | ||
DATE_FORMAT_MEDIUM_WITH_TIME, | ||
DATE_FORMAT_YEAR_MONTH, | ||
DATE_FORMAT_MONTH_YEAR, | ||
DATE_FORMAT_MONTH_ABBR_YEAR, | ||
DATE_FORMAT_DAY_MONTH, | ||
DATE_FORMAT_INTERACTION_TIMESTAMP, | ||
} from '../date-utils' | ||
|
||
describe('formatDate', () => { | ||
const date = '2024-12-04' | ||
const time = 'T10:41:45.425717Z' | ||
const dateAndTime = `${date}${time}` | ||
|
||
it("should render '04 Dec 2024' (default format)", () => { | ||
expect(formatDate(date)).to.equal('04 Dec 2024') // the default | ||
}) | ||
|
||
it("should render '04 Dec 2024' (DATE_FORMAT_COMPACT)", () => { | ||
expect(formatDate(date, DATE_FORMAT_COMPACT)).to.equal('04 Dec 2024') | ||
}) | ||
|
||
it("should render '4 Dec 2024' (DATE_FORMAT_MEDIUM)", () => { | ||
expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM)).to.equal('4 Dec 2024') | ||
}) | ||
|
||
it("should render '4 Dec 2024, 10:41am' (DATE_FORMAT_MEDIUM_WITH_TIME)", () => { | ||
expect(formatDate(dateAndTime, DATE_FORMAT_MEDIUM_WITH_TIME)).to.equal( | ||
'4 Dec 2024, 10:41am' | ||
) | ||
}) | ||
|
||
it("should render '4 December 2024' (DATE_FORMAT_FULL)", () => { | ||
expect(formatDate(date, DATE_FORMAT_FULL)).to.equal('4 December 2024') | ||
}) | ||
|
||
it("should render 'Wed, 04 Dec 2024' (DATE_FORMAT_FULL_DAY)", () => { | ||
expect(formatDate(date, DATE_FORMAT_FULL_DAY)).to.equal('Wed, 04 Dec 2024') | ||
}) | ||
|
||
it("should render '2024-12-04' (DATE_FORMAT_ISO)", () => { | ||
expect(formatDate(date, DATE_FORMAT_ISO)).to.equal('2024-12-04') | ||
}) | ||
|
||
it("should render '2024-12' (DATE_FORMAT_YEAR_MONTH)", () => { | ||
expect(formatDate(date, DATE_FORMAT_YEAR_MONTH)).to.equal('2024-12') | ||
}) | ||
|
||
it("should render 'December 2024' (DATE_FORMAT_MONTH_YEAR)", () => { | ||
expect(formatDate(date, DATE_FORMAT_MONTH_YEAR)).to.equal('December 2024') | ||
}) | ||
|
||
it("should render 'Dec 2024' (DATE_FORMAT_MONTH_ABBR_YEAR)", () => { | ||
expect(formatDate(date, DATE_FORMAT_MONTH_ABBR_YEAR)).to.equal('Dec 2024') | ||
}) | ||
|
||
it("should render '04 Dec' (DATE_FORMAT_DAY_MONTH)", () => { | ||
expect(formatDate(date, DATE_FORMAT_DAY_MONTH)).to.equal('04 Dec') | ||
}) | ||
|
||
it("should render '2024-12-4' (DATE_FORMAT_INTERACTION_TIMESTAMP)", () => { | ||
expect(formatDate(date, DATE_FORMAT_INTERACTION_TIMESTAMP)).to.equal( | ||
'2024-12-4' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const { format, parseISO } = require('date-fns') | ||
|
||
/** | ||
* Full date format with day and full month name. | ||
* Example: 4 December 2024 | ||
*/ | ||
const DATE_FORMAT_FULL = 'd MMMM yyyy' | ||
|
||
/** | ||
* Full date format including the weekday. | ||
* Example: Wed, 04 Dec 2024 | ||
*/ | ||
const DATE_FORMAT_FULL_DAY = 'E, dd MMM yyyy' | ||
|
||
/** | ||
* Compact date format with two-digit day and abbreviated month name. | ||
* Example: 04 Dec 2024 | ||
*/ | ||
const DATE_FORMAT_COMPACT = 'dd MMM yyyy' | ||
|
||
/** | ||
* ISO standard date format. | ||
* Example: 2024-12-04 | ||
*/ | ||
const DATE_FORMAT_ISO = 'yyyy-MM-dd' | ||
|
||
/** | ||
* Medium date format with single-digit day and abbreviated month name. | ||
* Example: 4 Dec 2024 | ||
*/ | ||
const DATE_FORMAT_MEDIUM = 'd MMM yyyy' | ||
|
||
/** | ||
* Medium date format with time included in 12-hour format. | ||
* Example: 4 Dec 2024, 3:30PM | ||
*/ | ||
const DATE_FORMAT_MEDIUM_WITH_TIME = 'd MMM yyyy, h:mmaaa' | ||
|
||
/** | ||
* Year and month format for compact representations. | ||
* Example: 2024-12 | ||
*/ | ||
const DATE_FORMAT_YEAR_MONTH = 'yyyy-MM' | ||
|
||
/** | ||
* Month and year format with full month name. | ||
* Example: December 2024 | ||
*/ | ||
const DATE_FORMAT_MONTH_YEAR = 'MMMM yyyy' | ||
|
||
/** | ||
* Abbreviated month and year format. | ||
* Example: Dec 2024 | ||
*/ | ||
const DATE_FORMAT_MONTH_ABBR_YEAR = 'MMM yyyy' | ||
|
||
/** | ||
* Day and month format with abbreviated month name. | ||
* Example: 04 Dec | ||
*/ | ||
const DATE_FORMAT_DAY_MONTH = 'dd MMM' | ||
|
||
/** | ||
* Interaction timestamp format with single-digit day and month. | ||
* Example: 2024-12-4 | ||
*/ | ||
const DATE_FORMAT_INTERACTION_TIMESTAMP = 'y-MM-d' | ||
|
||
/** | ||
* Formats a given date string into a specified format using `date-fns`. | ||
* | ||
* @param {string} dateISO - The date string in ISO format (e.g., '2024-12-04'). | ||
* @param {string} [dateISOFormat=DATE_FORMAT_COMPACT] - The format to use for formatting the date. | ||
* Available format constants include: | ||
* - `DATE_FORMAT_FULL`: Full date with day and full month name (e.g., '4 December 2024'). | ||
* - `DATE_FORMAT_FULL_DAY`: Full date with weekday included (e.g., 'Wed, 04 Dec 2024'). | ||
* - `DATE_FORMAT_COMPACT`: Compact date with abbreviated month name (e.g., '04 Dec 2024'). | ||
* - `DATE_FORMAT_ISO`: ISO standard format (e.g., '2024-12-04'). | ||
* - `DATE_FORMAT_MEDIUM`: Medium date format with single-digit day (e.g., '4 Dec 2024'). | ||
* - `DATE_FORMAT_MEDIUM_WITH_TIME`: Medium date with 12-hour time (e.g., '4 Dec 2024, 3:30PM'). | ||
* - `DATE_FORMAT_YEAR_MONTH`: Year and month format (e.g., '2024-12'). | ||
* - `DATE_FORMAT_MONTH_YEAR`: Full month and year (e.g., 'December 2024'). | ||
* - `DATE_FORMAT_MONTH_ABBR_YEAR`: Abbreviated month and year (e.g., 'Dec 2024'). | ||
* - `DATE_FORMAT_DAY_MONTH`: Day and abbreviated month (e.g., '04 Dec'). | ||
* - `DATE_FORMAT_INTERACTION_TIMESTAMP`: Interaction timestamp format (e.g., '2024-12-4'). | ||
* @returns {string} - The formatted date string. | ||
* | ||
* @example | ||
* // Format a date to the default compact format | ||
* formatDate('2024-12-04') | ||
* // Returns: '04 Dec 2024' | ||
* | ||
* @example | ||
* // Format a date to a full format | ||
* formatDate('2024-12-04', DATE_FORMAT_FULL) | ||
* // Returns: '4 December 2024' | ||
* | ||
* @example | ||
* // Format a date with abbreviated month and year | ||
* formatDate('2024-12-04', DATE_FORMAT_MONTH_ABBR_YEAR) | ||
* // Returns: 'Dec 2024' | ||
*/ | ||
function formatDate(dateISO, dateISOFormat = DATE_FORMAT_COMPACT) { | ||
return format(parseISO(dateISO), dateISOFormat) | ||
} | ||
|
||
module.exports = { | ||
DATE_FORMAT_FULL, | ||
DATE_FORMAT_FULL_DAY, | ||
DATE_FORMAT_COMPACT, | ||
DATE_FORMAT_ISO, | ||
DATE_FORMAT_MEDIUM, | ||
DATE_FORMAT_MEDIUM_WITH_TIME, | ||
DATE_FORMAT_YEAR_MONTH, | ||
DATE_FORMAT_MONTH_YEAR, | ||
DATE_FORMAT_MONTH_ABBR_YEAR, | ||
DATE_FORMAT_DAY_MONTH, | ||
DATE_FORMAT_INTERACTION_TIMESTAMP, | ||
formatDate, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.