Skip to content
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

LibWeb: Implement valueAsNumber for month and week <input> element types #3485

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

shannonbooth
Copy link
Contributor

No description provided.

@shannonbooth shannonbooth marked this pull request as draft February 7, 2025 12:26
These can be useful outside of the scope of the function these are
used.
This is intended to be used by the <input> element 'week' type state
and convert that to milliseconds from the Unix epoch (ignoring leap
seconds).

I am certain there is a much better way of writing this that does
not need a loop, but I am less convinced about writing that without
running into some edge case I didn't consider.
One point to note is that I am not entirely sure what the result
of the pre-existing valueAsNumber test should be for this strange
case which does not lie exactly on a week/day boundary. Chrome
gives a negative timestamp, which seems more wrong than the result
we give, and neither gecko or WebKit appear to support the 'week'
type. So I'm considering this result acceptable for now, and this
may be something that will need more WPT tests added in the future.
@shannonbooth shannonbooth marked this pull request as ready for review February 8, 2025 01:06

u32 number_of_months_since_unix_epoch(YearAndMonth year_and_month)
{
return (year_and_month.year - 1970) * 12 + year_and_month.month - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the year is 1969? Seems like this should return a signed result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, yeah this is wrong, I'll submit a MR to WPT to add a test for this case. It's also incorrect on the setter side to use fmod as that also doesn't handle the signed case, should instead be something like JS::modulo

@shannonbooth shannonbooth marked this pull request as draft February 10, 2025 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants