-
Notifications
You must be signed in to change notification settings - Fork 502
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
Add support for custom getTime #162
Conversation
Thanks! Rather than having a timeOffset, I think it would be better to instead allow a custom function to be passed, returning the time integer. If not provided it would simply be: What do you think? |
Well, indeed, it would be a more generic solution. Yet, since both the server time and the local time are monotonically increasing and the offset between them is always a constant value, this one also appears to solve almost all cases. Now, I think providing a function returning a promise would be the best choice as it would also let us later remove the option This promise-based solution will allow people to query their own time server if they ever need to, thus seems a great solution. Deal? (: |
Because the underlying code is using getTime: () => Date.now() + TIME_OFFSET
getTime: async () => {
const time = await fetch('mycustom-ntpserver.com')
return time + TIME_OFFSET
} This gives the most customization capabilities while keeping it simple |
Looks good! Do you mind putting the default Also about typings, will it be an issue if the provided |
Almost perfect :D Rather than having the ternary checking the typeof, why not keep it a default like you were doing? |
'cause NOT everyone uses TypeScript. (: Just kidding, pushing it now one last time! Thanks for all your feedbacks. |
❤️ |
This support for the optional field
timeOffset
allows consumers of the API to avoid unnecessary calls to the/api/v1/time
endpoint for each private call. One can call thetime
method only once at startup and then calculate an offset between the local time and the returned value which, if provided as an option, will be used for any future private call.