Skip to content

Commit

Permalink
core: resort date formats and add DD.MM.YYYY format (fixes #4744)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Sep 13, 2024
1 parent a86d9a9 commit 3fe5352
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
21 changes: 7 additions & 14 deletions packages/core/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,21 @@ export const EVENTS = {
systemTimeInvalid: "system:invalidTime"
};

const separators = ["-", "/"];
const separators = ["-", "/", "."];
const DD = "DD";
const MM = "MM";
const YYYY = "YYYY";
export const DATE_FORMATS = [
...separators
.map((sep) => [
[DD, MM, YYYY].join(sep),
[MM, DD, YYYY].join(sep),
[YYYY, MM, DD].join(sep)
])
...[
[DD, MM, YYYY],
[MM, DD, YYYY],
[YYYY, MM, DD]
]
.map((item) => separators.map((sep) => item.join(sep)))
.flat(),
"MMM D, YYYY"
];

export const DATE_FORMATS_WITHOUT_YEAR = [
...separators
.map((sep) => [[DD, MM].join(sep), [MM, DD].join(sep), [MM, DD].join(sep)])
.flat(),
"MMM D"
];

export const TIME_FORMATS = ["12-hour", "24-hour"];

export const CURRENT_DATABASE_VERSION = 6.1;
9 changes: 1 addition & 8 deletions packages/core/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import dayjs from "dayjs";
import { DATE_FORMATS, DATE_FORMATS_WITHOUT_YEAR } from "../common";

export type TimeFormat = "12-hour" | "24-hour";

Expand Down Expand Up @@ -70,7 +69,7 @@ export type TimeOptions = {
timeFormat: TimeFormat;
};
export type DateOptions = {
type: "date" | "date-without-year";
type: "date";
dateFormat: string;
};
export type DateTimeOptions = {
Expand All @@ -97,12 +96,6 @@ export function formatDate(
return dayjs(date).format(getTimeFormat(options.timeFormat));
case "date":
return dayjs(date).format(options.dateFormat);
case "date-without-year": {
const format =
DATE_FORMATS_WITHOUT_YEAR[DATE_FORMATS.indexOf(options.dateFormat)];
if (!format) return dayjs(date).format("MM-DD");
return dayjs(date).format(format);
}
}
}

Expand Down

0 comments on commit 3fe5352

Please sign in to comment.