I am trying to sync my client app time to my server time (it matters because the app is serverless and has offline-work). On the app startup I calculate the time difference and then override the Date.now()
method to add the difference into original now. For example assume this code:
Date.__serverDifference = calculateServerDifference();
Date.__now = Date.now;
Date.now = () => Date.__now() + Date.__serverDifference;
and it works fine. But the problem is about other Date functionalities. For example if I use new Date()
it will return original time and it doesn't care the overridden now method.
As the MDN documentation says:
JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.
Is there any way to override the js Date Class to return all current times according to this new calculation?