Skip to content

Commit

Permalink
date format day of year (Avaiga#1436)
Browse files Browse the repository at this point in the history
* Support day of yer in date format 'D'

* Support day of yer in date format 'D'

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Jun 20, 2024
1 parent 42e1d8d commit 7e43f3a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions frontend/taipy-gui/src/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ describe("getDateTimeString", () => {
expect(myWarn).toHaveBeenCalledWith("Invalid date format:", "Invalid time value")
});
it("returns for bad format", async () => {
expect(getDateTimeString("2024-10-05", "D", getDateFormatConfig())).toContain("05 2024");
expect(getDateTimeString("2024-10-05", "ABCDEF", getDateFormatConfig())).toContain("05 2024");
expect(myWarn).toHaveBeenCalled()
expect(myWarn.mock.lastCall).toHaveLength(2)
expect(myWarn.mock.lastCall[0]).toBe("Invalid date format:")
expect(myWarn.mock.lastCall[1]).toContain("Use `d` instead of `D`")
expect(myWarn.mock.lastCall[1]).toContain("Format string contains an unescaped latin alphabet character `A`")
});
it("returns for null", async () => {
expect(getDateTimeString(null as unknown as string, "dd-MM-yy", getDateFormatConfig())).toBe("null");
Expand Down
5 changes: 3 additions & 2 deletions frontend/taipy-gui/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ export const getDateTimeString = (
return formatInTimeZone(
dateVal || "",
formatConf.forceTZ || !tz ? formatConf.timeZone : tz,
datetimeformat || formatConf.dateTime
datetimeformat || formatConf.dateTime,
{ useAdditionalDayOfYearTokens: true }
);
}
return format(dateVal || 0, datetimeformat || formatConf.date);
return format(dateVal || 0, datetimeformat || formatConf.date, { useAdditionalDayOfYearTokens: true });
} catch (e) {
console.warn("Invalid date format:", (e as Error).message || e);
return `${dateVal}`;
Expand Down

0 comments on commit 7e43f3a

Please sign in to comment.