Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
302d92ea
Commit
302d92ea
authored
Jan 10, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create function to format dates in a standard sortable format
parent
2b92198d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
time-test.js
src/sidebar/util/test/time-test.js
+13
-0
time.ts
src/sidebar/util/time.ts
+13
-0
No files found.
src/sidebar/util/test/time-test.js
View file @
302d92ea
...
...
@@ -2,6 +2,7 @@ import {
clearFormatters
,
decayingInterval
,
formatDate
,
formatDateTime
,
formatRelativeDate
,
nextFuzzyUpdate
,
}
from
'../time'
;
...
...
@@ -255,4 +256,16 @@ describe('sidebar/util/time', () => {
);
});
});
describe
(
'formatDateTime'
,
()
=>
{
[
new
Date
(
Date
.
UTC
(
2023
,
11
,
20
,
3
,
5
,
38
)),
new
Date
(
'2020-05-04T23:02:01+05:00'
),
].
forEach
(
date
=>
{
it
(
'returns right format for provided date'
,
()
=>
{
const
expectedDateRegex
=
/^
\d{4}
-
\d{2}
-
\d{2}
\d{2}
:
\d{2}
$/
;
assert
.
match
(
formatDateTime
(
date
),
expectedDateRegex
);
});
});
});
});
src/sidebar/util/time.ts
View file @
302d92ea
...
...
@@ -262,3 +262,16 @@ export function formatDate(date: Date, Intl?: IntlType): string {
Intl
,
);
}
/**
* Formats a date as `YYYY-MM-DD hh:mm`, using 24h and system timezone.
*/
export
function
formatDateTime
(
date
:
Date
):
string
{
const
year
=
date
.
getFullYear
();
const
month
=
`
${
date
.
getMonth
()
+
1
}
`
.
padStart
(
2
,
'0'
);
const
day
=
`
${
date
.
getDate
()}
`
.
padStart
(
2
,
'0'
);
const
hours
=
`
${
date
.
getHours
()}
`
.
padStart
(
2
,
'0'
);
const
minutes
=
`
${
date
.
getMinutes
()}
`
.
padStart
(
2
,
'0'
);
return
`
${
year
}
-
${
month
}
-
${
day
}
${
hours
}
:
${
minutes
}
`
;
}
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