Repository navigation
WS-3039 - Timestamp: add year posted logic #14646
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
Open
holchris
wants to merge
14
commits into
latest
Choose a base branch
from
WS-3039-timestamp-add-year-posted-logic
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8525544
adds isYearPublished logic
holchris 71c5b04
unit tests
holchris e35f746
correct formats for japanese, korean and chinese
LilyL0u 30ba768
persian/pashto with different calendars also omits year. tests. readm…
LilyL0u 7177803
hungarian and sinhala different formats
LilyL0u eb4450e
also remove current year from most read and have formats as shared ut…
LilyL0u fd9adf4
move timestamp formats to servce configs
LilyL0u 68bce3d
update snapshots
LilyL0u e5d6727
date suffix pidgin fix
LilyL0u 8a5f6dc
Trigger CI
holchris 13298a5
Merge remote-tracking branch 'origin/latest' into WS-3039-timestamp-a…
LilyL0u 9a2d4a5
readme update
LilyL0u 93c9c0d
Merge branch 'WS-3039-timestamp-add-year-posted-logic' of github.com:…
LilyL0u be5e109
Revert spurious Watch nav link snapshot entry for pidgin mostReadPage
LilyL0u 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
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
41 changes: 29 additions & 12 deletions
41
src/app/components/MostRead/Canonical/LastUpdated/index.tsx
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 |
|---|---|---|
| @@ -1,28 +1,45 @@ | ||
| import moment from 'moment-timezone'; | ||
| import getDayAndMonthFormat from '#lib/utilities/getDayAndMonthFormat'; | ||
| import Timestamp from '#app/components/TimestampContainer'; | ||
|
|
||
| interface LastUpdatedProps { | ||
| locale: string; | ||
| prefix: string; | ||
| timestamp: number | string; | ||
| timezone: string; | ||
| datetimeMonthDayFormat?: string; | ||
| } | ||
|
|
||
| const LastUpdated = ({ | ||
| locale, | ||
| prefix, | ||
| timestamp, | ||
| timezone, | ||
| }: LastUpdatedProps) => ( | ||
| <Timestamp | ||
| timestamp={timestamp} | ||
| dateTimeFormat="YYYY-MM-DD" | ||
| prefix={prefix} | ||
| format="LL" | ||
| locale={locale} | ||
| timezone={timezone} | ||
| padding={false} | ||
| altCalendar={null} | ||
| /> | ||
| ); | ||
| datetimeMonthDayFormat, | ||
| }: LastUpdatedProps) => { | ||
| const publicationDate = moment(timestamp).locale(locale).tz(timezone); | ||
| const isPublishedThisYear = publicationDate.isSame( | ||
| moment().tz(timezone), | ||
| 'year', | ||
| ); | ||
|
|
||
| return ( | ||
| <Timestamp | ||
| timestamp={timestamp} | ||
| dateTimeFormat="YYYY-MM-DD" | ||
| prefix={prefix} | ||
| format={ | ||
| isPublishedThisYear | ||
| ? datetimeMonthDayFormat || getDayAndMonthFormat(locale) | ||
| : 'LL' | ||
| } | ||
| locale={locale} | ||
| timezone={timezone} | ||
| isPublishedThisYear={isPublishedThisYear} | ||
| padding={false} | ||
| altCalendar={null} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default LastUpdated; | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a bit precise, no?
The date is coming through as
why aren't we string comparing the first 4 characters to the current year rather than importing the big moment lib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gets the precise local time so that this works at year boundaries where different timezones start a new year at different times. But if we don't want to use moment, we can go with Aaron's suggestion of Intl.DateTimeFormat instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have misunderstood, but it sounds like we would be spending a fair amount of computation (relatively) for some edge cases that are published on Dec 31st and Jan 1st.
The rest of the year we're shouldering that burden unnecessarily
That said, the computation and any additional bundle size could be very minor.
Would you be able to run a simulation to work out what kind of burden we're looking at (for us on server and for the audience in terms of bundle size changes)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just got copilot to run a simulation and it found that it would be no more of a burden than the current implementation
Here is a summary of why