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
88d7875a
Commit
88d7875a
authored
Oct 02, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Oct 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename standalone formatDateTime to formatSortableDateTime
parent
8baa0854
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
32 deletions
+44
-32
AnnotationTimestamps-test.js
...r/components/Annotation/test/AnnotationTimestamps-test.js
+15
-12
annotations-exporter.tsx
src/sidebar/services/annotations-exporter.tsx
+10
-6
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+2
-2
time-test.js
src/sidebar/util/test/time-test.js
+9
-11
time.ts
src/sidebar/util/time.ts
+8
-1
No files found.
src/sidebar/components/Annotation/test/AnnotationTimestamps-test.js
View file @
88d7875a
...
...
@@ -6,7 +6,9 @@ import AnnotationTimestamps, { $imports } from '../AnnotationTimestamps';
describe
(
'AnnotationTimestamps'
,
()
=>
{
let
clock
;
let
fakeTime
;
let
fakeFormatDateTime
;
let
fakeFormatRelativeDate
;
let
fakeDecayingInterval
;
const
createComponent
=
props
=>
mount
(
...
...
@@ -21,15 +23,16 @@ describe('AnnotationTimestamps', () => {
beforeEach
(()
=>
{
clock
=
sinon
.
useFakeTimers
();
fakeTime
=
{
formatDateTime
:
sinon
.
stub
().
returns
(
'absolute date'
),
formatRelativeDate
:
sinon
.
stub
().
returns
(
'fuzzy string'
),
decayingInterval
:
sinon
.
stub
(),
};
fakeFormatDateTime
=
sinon
.
stub
().
returns
(
'absolute date'
);
fakeFormatRelativeDate
=
sinon
.
stub
().
returns
(
'fuzzy string'
);
fakeDecayingInterval
=
sinon
.
stub
();
$imports
.
$mock
({
'@hypothesis/frontend-shared'
:
fakeTime
,
'@hypothesis/frontend-shared'
:
{
formatDateTime
:
fakeFormatDateTime
,
formatRelativeDate
:
fakeFormatRelativeDate
,
decayingInterval
:
fakeDecayingInterval
,
},
});
});
...
...
@@ -58,7 +61,7 @@ describe('AnnotationTimestamps', () => {
});
it
(
'renders edited timestamp if `withEditedTimestamp` is true'
,
()
=>
{
fake
Time
.
f
ormatRelativeDate
.
onCall
(
1
).
returns
(
'another fuzzy string'
);
fake
F
ormatRelativeDate
.
onCall
(
1
).
returns
(
'another fuzzy string'
);
const
wrapper
=
createComponent
({
withEditedTimestamp
:
true
});
...
...
@@ -68,7 +71,7 @@ describe('AnnotationTimestamps', () => {
});
it
(
'does not render edited relative date if equivalent to created relative date'
,
()
=>
{
fake
Time
.
f
ormatRelativeDate
.
returns
(
'equivalent fuzzy strings'
);
fake
F
ormatRelativeDate
.
returns
(
'equivalent fuzzy strings'
);
const
wrapper
=
createComponent
({
withEditedTimestamp
:
true
});
...
...
@@ -78,12 +81,12 @@ describe('AnnotationTimestamps', () => {
});
it
(
'is updated after time passes'
,
()
=>
{
fake
Time
.
d
ecayingInterval
.
callsFake
((
date
,
callback
)
=>
{
fake
D
ecayingInterval
.
callsFake
((
date
,
callback
)
=>
{
const
id
=
setTimeout
(
callback
,
10
);
return
()
=>
clearTimeout
(
id
);
});
const
wrapper
=
createComponent
();
fake
Time
.
f
ormatRelativeDate
.
returns
(
'60 jiffies'
);
fake
F
ormatRelativeDate
.
returns
(
'60 jiffies'
);
act
(()
=>
{
clock
.
tick
(
1000
);
...
...
src/sidebar/services/annotations-exporter.tsx
View file @
88d7875a
...
...
@@ -15,7 +15,7 @@ import { annotationDisplayName } from '../helpers/annotation-user';
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
{
renderMathAndMarkdown
}
from
'../render-markdown'
;
import
{
formatDateTime
}
from
'../util/time'
;
import
{
format
Sortable
DateTime
}
from
'../util/time'
;
export
type
JSONExportContent
=
{
export_date
:
string
;
...
...
@@ -91,7 +91,7 @@ export class AnnotationsExporter {
const
page
=
pageLabel
(
annotation
);
const
annotationQuote
=
quote
(
annotation
);
const
lines
=
[
`Created at:
${
formatDateTime
(
new
Date
(
annotation
.
created
))}
`
,
`Created at:
${
format
Sortable
DateTime
(
new
Date
(
annotation
.
created
))}
`
,
`Author:
${
extractUsername
(
annotation
)}
`
,
page
?
`Page:
${
page
}
`
:
undefined
,
`Type:
${
annotationRole
(
annotation
)}
`
,
...
...
@@ -108,7 +108,7 @@ export class AnnotationsExporter {
});
return
trimAndDedent
`
${
formatDateTime
(
now
)}
${
format
Sortable
DateTime
(
now
)}
${
title
}
${
uri
}
Group:
${
groupName
}
...
...
@@ -135,7 +135,7 @@ export class AnnotationsExporter {
});
const
annotationToRow
=
(
annotation
:
APIAnnotationData
)
=>
[
formatDateTime
(
new
Date
(
annotation
.
created
)),
format
Sortable
DateTime
(
new
Date
(
annotation
.
created
)),
extractUsername
(
annotation
),
pageLabel
(
annotation
)
??
''
,
uri
,
...
...
@@ -192,7 +192,9 @@ export class AnnotationsExporter {
<
section
>
<
h1
>
Summary
</
h1
>
<
p
>
<
time
dateTime=
{
now
.
toISOString
()
}
>
{
formatDateTime
(
now
)
}
</
time
>
<
time
dateTime=
{
now
.
toISOString
()
}
>
{
formatSortableDateTime
(
now
)
}
</
time
>
</
p
>
<
p
>
<
strong
>
{
title
}
</
strong
>
...
...
@@ -253,7 +255,9 @@ export class AnnotationsExporter {
<
td
>
Created at:
</
td
>
<
td
>
<
time
dateTime=
{
annotation
.
created
}
>
{
formatDateTime
(
new
Date
(
annotation
.
created
))
}
{
formatSortableDateTime
(
new
Date
(
annotation
.
created
),
)
}
</
time
>
</
td
>
</
tr
>
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
88d7875a
...
...
@@ -4,7 +4,7 @@ import {
newReply
,
publicAnnotation
,
}
from
'../../test/annotation-fixtures'
;
import
{
formatDateTime
}
from
'../../util/time'
;
import
{
format
Sortable
DateTime
}
from
'../../util/time'
;
import
{
AnnotationsExporter
}
from
'../annotations-exporter'
;
describe
(
'AnnotationsExporter'
,
()
=>
{
...
...
@@ -30,7 +30,7 @@ describe('AnnotationsExporter', () => {
beforeEach
(()
=>
{
now
=
new
Date
();
formattedNow
=
formatDateTime
(
now
);
formattedNow
=
format
Sortable
DateTime
(
now
);
baseAnnotation
=
{
...
newAnnotation
(),
...
publicAnnotation
(),
...
...
src/sidebar/util/test/time-test.js
View file @
88d7875a
import
{
formatDateTime
}
from
'../time'
;
import
{
format
Sortable
DateTime
}
from
'../time'
;
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
);
});
describe
(
'formatSortableDateTime'
,
()
=>
{
[
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
(
formatSortableDateTime
(
date
),
expectedDateRegex
);
});
});
});
src/sidebar/util/time.ts
View file @
88d7875a
/**
* Formats a date as `YYYY-MM-DD hh:mm`, using 24h and system timezone.
*
* This format has these useful characteristics:
* - Easy to read (compared to an ISO date).
* - Lexicographic and chronological order match.
* - It is detected and correctly parsed as "date" when pasted in common
* spreadsheet editors, making it useful when exporting dates for CSV
* documents.
*/
export
function
formatDateTime
(
date
:
Date
):
string
{
export
function
format
Sortable
DateTime
(
date
:
Date
):
string
{
const
year
=
date
.
getFullYear
();
const
month
=
`
${
date
.
getMonth
()
+
1
}
`
.
padStart
(
2
,
'0'
);
const
day
=
`
${
date
.
getDate
()}
`
.
padStart
(
2
,
'0'
);
...
...
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