Comments (10)
It happens because of JavaScript date math and the reliance on difference between .getMonth()
calls after .setMonth()
calls for relative time rounding, in this case when duration.days === 0
and duration.months === -1
and relativeTo === new Date('2024-05-31')
[I] lily@bina ~> node
Welcome to Node.js v22.2.0.
Type ".help" for more information.
> let date = new Date()
undefined
> date
2024-05-31T18:32:29.029Z
> date.getMonth()
4
> date.setMonth(3)
1714588349029
> date.getMonth()
4
> date
2024-05-01T18:32:29.029Z
>
I've got a patch cooked up to fix this anomaly by correcting "May 31 minus 1 month" to be equal to "April 30" rather than "May 1". I don't know if that is semantically what is desired by this library, but I've never touched or used this library before really so I don't know very well what would be "expected" outputs
from relative-time-element.
I've opened #285 to fix this behavior
from relative-time-element.
This is all over github right now. April 30th in my repo renders as "yesterday".
If I'm reading this correctly, this is happening because "less than one month ago" is being considered the equivalent of "this month". That shortcut equivalence is obviously flawed. Tweaking the definition of "one month ago" is not the solution. Making a better calculation for "this month" is.
I assume "this month" should be based on converting "now" into a timestamp with the same time zone as the given timestamp, and then asking for only the month value and comparing the two, yes?
from relative-time-element.
Might be related: https://twitter.com/depoulo/status/1620703935186231302
from relative-time-element.
May be the library or the component handling the relative-time is not updating it correctly instead we can a create a custom script to handle the time Am i correct mam/sir?
from relative-time-element.
Bug is reproducible on GitHub today:
![image](https://private-user-images.githubusercontent.com/115237/335572538-f0fa08e6-8290-4a56-b2d5-bd9fa3a5a44c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg2MjQwNjcsIm5iZiI6MTcxODYyMzc2NywicGF0aCI6Ii8xMTUyMzcvMzM1NTcyNTM4LWYwZmEwOGU2LTgyOTAtNGE1Ni1iMmQ1LWJkOWZhM2E1YTQ0Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYxN1QxMTI5MjdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03ODlhMDkwNjBmYzlmYzMzYzUxMjk2YTY5M2M0YTM5YmQyYWVlMGE3NGFlODA0NzA4YmQzZGY3MjMyOGEwZGVkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.JfpJdccWDzdyacAyywCRxAM3PrCRN6x_gHHVxjIMdvI)
currently it's 2024-05-31T12:16:54.112Z
2024-05-01T12:32:52.000Z
renders "30 days ago" which is ok
2024-05-01T05:33:40.000Z
renders "now" but should be "31 days ago" or "a month ago"
2024-04-30T12:39:36.000Z
renders "yesterday" but should be "32 days ago" or "a month ago"
It only happens when the current date is near the end of a month. It looks like all subsequent dates after the point where it breaks are off by 1 month.
from relative-time-element.
I think the true fix is to standardize the month to be 28 days consistently but in the interim this needs some serious test coverage.
It's May 31st and April 30th is yesterday..
from relative-time-element.
That would work. We could call the extra 13th month "Decemburary", and the one leftover day in the year could be called "bonus day", during which absolutely nothing works, so it's a worldwide holiday. We could even tweak the length of "bonus day" to fix the whole leap-year problem!
from relative-time-element.
Month 13th could be nulluary or "Month Does Not Exist". Last day of year we take the day off to celebrate vanquishing all timedate bugs.
from relative-time-element.
If it worked for the Eastman Kodak Company, it could work for GitHub 🤷🏽
from relative-time-element.
Related Issues (20)
- Format attribute does not respect lang HOT 3
- Make `format` API more consistent
- datetime without weekday HOT 2
- Package no longer publishing to NPM? HOT 3
- Not exactly sure of what, but something appears to be wrong?
- Wrong human text HOT 5
- Precision for what to display HOT 3
- The `on` prefix is not localized HOT 3
- Attribute to control which attribute is set for `title` HOT 2
- Text selection bugs in Firefox HOT 5
- Enable passing `formatStyle` to Intl.DateTimeFormat HOT 1
- Stray days added to duration HOT 1
- Stricter `datetime` validation HOT 4
- sdfgvb
- Cannot get format=relative to display seconds HOT 2
- "X years ago" is not rounding correctly HOT 3
- Title format is not configurable
- Render 12/24 hour format according to user's preference HOT 4
- precision=day should return "today" instead of "now" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relative-time-element.