fix #100 (#180)
All checks were successful
Publish latest version / build (push) Successful in 1m30s
All checks were successful
Publish latest version / build (push) Successful in 1m30s
Close #100 We use Intl.DateTimeFormat to format the date, using the local provided from 1st: the guild info 2nd: the default lang used for Botanique Reviewed-on: #180 Co-authored-by: Mylloon <kennel.anri@tutanota.com> Co-committed-by: Mylloon <kennel.anri@tutanota.com>
This commit is contained in:
parent
b1abeefad2
commit
a08d0c0e9b
1 changed files with 11 additions and 2 deletions
|
@ -5,8 +5,16 @@
|
||||||
* @param date Date
|
* @param date Date
|
||||||
* @returns String
|
* @returns String
|
||||||
*/
|
*/
|
||||||
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) =>
|
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
|
||||||
date.toLocaleString(tz).replace(" ", ` ${locale.get("u_time_at")} `);
|
const formattedDate = new Intl.DateTimeFormat(tz, {
|
||||||
|
dateStyle: "short",
|
||||||
|
timeStyle: "medium",
|
||||||
|
})
|
||||||
|
.format(date)
|
||||||
|
.split(" ");
|
||||||
|
|
||||||
|
return `${formattedDate[0]} ${locale.get("u_time_at")} ${formattedDate[1]}`;
|
||||||
|
};
|
||||||
|
|
||||||
enum TimeSecond {
|
enum TimeSecond {
|
||||||
Year = 31536000,
|
Year = 31536000,
|
||||||
|
@ -63,5 +71,6 @@ export const strToSeconds = (time: string) => {
|
||||||
export const timeDeltaToString = (time: number) => {
|
export const timeDeltaToString = (time: number) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
// TODO adapt the output and not always parse the time as seconds
|
// TODO adapt the output and not always parse the time as seconds
|
||||||
|
// Use Intl.RelativeTimeFormat ?
|
||||||
return `${strToSeconds(`${(now - time) / 1000}`)} secs`;
|
return `${strToSeconds(`${(now - time) / 1000}`)} secs`;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue