Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
f5b5bd64
Commit
f5b5bd64
authored
Jan 18, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak datetime.ts
parent
d31d9eb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
40 deletions
+14
-40
datetime.ts
web/src/helpers/datetime.ts
+14
-40
No files found.
web/src/helpers/datetime.ts
View file @
f5b5bd64
...
@@ -42,38 +42,19 @@ export function getTimeString(t?: Date | number | string): string {
...
@@ -42,38 +42,19 @@ export function getTimeString(t?: Date | number | string): string {
* - "pl" locale: "30.01.2023, 22:05:00"
* - "pl" locale: "30.01.2023, 22:05:00"
*/
*/
export
function
getDateTimeString
(
t
?:
Date
|
number
|
string
|
any
,
locale
=
i18n
.
language
):
string
{
export
function
getDateTimeString
(
t
?:
Date
|
number
|
string
|
any
,
locale
=
i18n
.
language
):
string
{
const
tsFromDate
=
getTimeStampByDate
(
t
?
t
:
Date
.
now
());
const
tsFromDate
=
new
Date
(
getTimeStampByDate
(
t
?
t
:
Date
.
now
()));
try
{
return
new
Date
(
tsFromDate
).
toLocaleDateString
(
locale
,
{
return
tsFromDate
.
toLocaleString
(
locale
,
{
year
:
"numeric"
,
year
:
"numeric"
,
month
:
"numeric"
,
month
:
"numeric"
,
day
:
"numeric"
,
day
:
"numeric"
,
hour
:
"numeric"
,
hour
:
"numeric"
,
minute
:
"numeric"
,
minute
:
"numeric"
,
second
:
"numeric"
,
second
:
"numeric"
,
});
});
}
}
catch
(
error
)
{
return
tsFromDate
.
toLocaleString
();
/**
}
* Get a localized date string to provided time.
*
* If no date is provided, the current date is used.
*
* Note: This function does not include time information.
*
* Sample outputs:
* - "en" locale: "1/30/2023"
* - "pt-BR" locale: "30/01/2023"
* - "pl" locale: "30.01.2023"
*/
export
function
getDateString
(
t
?:
Date
|
number
|
string
,
locale
=
i18n
.
language
):
string
{
const
tsFromDate
=
getTimeStampByDate
(
t
?
t
:
Date
.
now
());
return
new
Date
(
tsFromDate
).
toLocaleDateString
(
locale
,
{
year
:
"numeric"
,
month
:
"numeric"
,
day
:
"numeric"
,
});
}
}
/**
/**
...
@@ -98,14 +79,7 @@ export const getRelativeTimeString = (time: number, locale = i18n.language, form
...
@@ -98,14 +79,7 @@ export const getRelativeTimeString = (time: number, locale = i18n.language, form
const
dayMillis
=
hourMillis
*
24
;
const
dayMillis
=
hourMillis
*
24
;
// Show full date if more than 1 day ago.
// Show full date if more than 1 day ago.
if
(
pastTimeMillis
>=
dayMillis
)
{
if
(
pastTimeMillis
>=
dayMillis
)
{
return
new
Date
(
time
).
toLocaleDateString
(
locale
,
{
return
getDateTimeString
(
time
,
locale
);
year
:
"numeric"
,
month
:
"numeric"
,
day
:
"numeric"
,
hour
:
"numeric"
,
minute
:
"numeric"
,
second
:
"numeric"
,
});
}
}
// numeric: "auto" provides "yesterday" for 1 day ago, "always" provides "1 day ago"
// numeric: "auto" provides "yesterday" for 1 day ago, "always" provides "1 day ago"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment