Date enhancements and support for Unix Timestamps#791
Conversation
lib/date.js
Outdated
There was a problem hiding this comment.
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. |
lib/date.js
Outdated
There was a problem hiding this comment.
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. |
lib/date.js
Outdated
There was a problem hiding this comment.
type = type || 'javascript'
There was a problem hiding this comment.
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 optionaltypeparameter to ensure proper date conversion for the given input value.closes #789