-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Date enhancements and support for Unix Timestamps #791
Conversation
|
||
value = parseInt(value, 10); | ||
value = Number(value); |
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.
Why ?
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 changed this to the Number constructor because parseInt
drops the decimals. After reviewing performance I've updated it to use parseFloat
.
Thinking about it, can't we just use the existing unit without adding any new api ? |
ccbdd54
to
78e750b
Compare
@Marsup PR has been updated and downstream merged with your recent commits to I've removed the approach that uses |
So what happened to my last comment ? |
I'm not sure I understand what you mean? Please explain. |
I don't think a new API is needed, just using the existing unit. |
I agree that replicating the This PR is clean, functional and has 100% test coverage. |
If you have objective reasoning for a different approach on handling timestamps let's discuss it. For instance, getting rid of the |
ISO is a strict format applied on a string hence its special treatment, a number is not timestamp by itself, any number is a timestamp. Actually, if you want a strict validation on that, I'm just now seeing that this could already be achieved by a
I do mean that the unit should translate to a multiplier. FWIW I'm not questioning the quality of the PR here, just the content. |
@Marsup I am pretty sure it is a bad idea to change the parsing of a date depending on the Also, |
It's been for annotation so far, is there any valid reason not to use it as it already exists ? |
Fractional, as in 123.45, which Joi never passes on to moment. |
Oh yeah, but with this patch it would. |
While using unit to set the timestamp multiplier is a valid approach, what are the reasons we should not add an explicit To me, |
I don't mind the timestamp per se, the flag behind it seems like a useless duplication of unit though. As common ground I'd propose timestamp takes whatever it can and translate it to unit, OK for everyone ? |
That can work. So to confirm, is the following acceptable? If so, I'll update the PR accordingly.
So for instance…
|
I'd still argue against changing the meaning of |
Honestly, I'm leaning that way as well. Avoiding unit feels cleaner and follows a better separation of concerns. "Piggy-backing" on unit introduces cross-over between the APIs and potential complications down the road if the functionality/purpose of one changes. To me, the question should come down to the |
Back-channeled a bit with @kanongil, let's stick to the current form, gonna review now. |
@@ -23,6 +23,12 @@ internals.isIsoDate = (() => { | |||
return date && (date.toString() === isoString); | |||
}; | |||
})(); | |||
internals.isTimestampAllowed = function (unit) { |
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.
Inline that, it's only used once.
Thanks for the review and line notes @Marsup!! I'll work on these changes and let you know when it's updated. |
@Marsup, PR is updated. Good call on adding some additional checks for ambiguous values. I've also updated the When all looks good let me know and I'll rebase down to a single commit so it keeps the history short. |
@@ -150,6 +159,19 @@ internals.Date.prototype.iso = function () { | |||
return obj; | |||
}; | |||
|
|||
internals.Date.prototype.timestamp = function (type) { | |||
|
|||
type = type ? type : 'javascript'; |
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.
type = type || 'javascript'
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.
Good call…will update.
- downstream merge and resolve conflicts - simplify timestamp API - refactor timestamp based on PR feedback - update date.base language to be timestamp generic - misc optimizations and updated tests - revert date.base error message
fe16faf
to
fa2fe7e
Compare
PR has been updated and rebased |
Date enhancements and support for Unix Timestamps
Thanks for the hard work. |
You're welcome!! Thanks for the feedback and reviewing my pull request! |
👍 |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Revised
This PR includes the following changes:
date()
validationdate.timestamp()
that supports both javascript and unix timestampsNote: Because javascript timestamps are millisecond-based and unix timestamps are second-based, the
timestamp()
constraint accepts an optionaltype
parameter to ensure proper date conversion for the given input value.closes #789