-
-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor/date fns #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor/date fns #1069
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1507cf8
replace date-fns usage with Intl.RelativeTimeFormat
scheidtdav 4205b56
remove date-fns from range-picker
scheidtdav e92ae2b
remove date-fns from mobile overview layer
scheidtdav 2ae3c26
process review
scheidtdav 29cba82
make sure the date is correctly translated
scheidtdav 8c666be
use a simpler approach for date time formatting
scheidtdav dabf422
add i18n.lnaguage to missing calls to toLocaleString()
scheidtdav b698123
Merge branch 'dev' into refactor/date-fns
scheidtdav 2e026c8
harden date formatting
scheidtdav 228a6d3
restore original 20 day offset
scheidtdav f2ff9d0
use more sensible number of days for months, years and quarters inter…
scheidtdav 53d1ae1
use hydrated state for rendering of timestamps
scheidtdav cffeb11
Merge branch 'dev' into refactor/date-fns
scheidtdav 5cf6600
fix missing import
scheidtdav 14454e4
use date and time in mobile overview layer
scheidtdav 5ca7c5f
remove quarters for textual representation of relative time intervals
scheidtdav a5eee71
reactivate oxlint rules of hooks
scheidtdav f2236c8
nevermind it should stay off for tests
scheidtdav b786a30
move hydrated state up one level
scheidtdav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const ONE_MINUTE_IN_S = 60 | ||
| const ONE_HOUR_IN_S = 60 * ONE_MINUTE_IN_S | ||
| const ONE_DAY_IN_S = 24 * ONE_HOUR_IN_S | ||
| const ONE_WEEK_IN_S = 7 * ONE_DAY_IN_S | ||
| const ONE_MONTH_IN_S = 4 * ONE_WEEK_IN_S | ||
| const ONE_QUARTER_IN_S = 3 * ONE_MONTH_IN_S | ||
| const ONE_YEAR_IN_S = 12 * ONE_MONTH_IN_S | ||
|
scheidtdav marked this conversation as resolved.
Outdated
|
||
|
|
||
| export const dateDiffToNowInWords = (locale: string, date: Date) => { | ||
| const r = new Intl.RelativeTimeFormat(locale) | ||
| const now = new Date() | ||
| const diffInSeconds = Math.round((now.getTime() - date.getTime()) / 1000) | ||
| const absDiffInSeconds = Math.abs(diffInSeconds) | ||
|
|
||
| if (absDiffInSeconds < ONE_MINUTE_IN_S) | ||
| return r.format(-diffInSeconds, 'second') | ||
| if (absDiffInSeconds < ONE_HOUR_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_MINUTE_IN_S), 'minute') | ||
| if (absDiffInSeconds < ONE_DAY_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_HOUR_IN_S), 'hour') | ||
| if (absDiffInSeconds < ONE_WEEK_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_DAY_IN_S), 'day') | ||
| if (absDiffInSeconds < ONE_MONTH_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_WEEK_IN_S), 'week') | ||
| if (absDiffInSeconds < ONE_QUARTER_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_MONTH_IN_S), 'month') | ||
| if (absDiffInSeconds < ONE_YEAR_IN_S) | ||
| return r.format(-Math.round(diffInSeconds / ONE_QUARTER_IN_S), 'quarter') | ||
|
scheidtdav marked this conversation as resolved.
Outdated
|
||
| return r.format(-Math.round(diffInSeconds / ONE_YEAR_IN_S), 'year') | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.