I want a custom behavior of the system function CurrDate(). The reason is that for testing the functionality that is dependent on today's date, I should be able to change the date to anything and test that functionality.
Is there a way I can do that?
Another thing I couldn't find is how to find all usages of CurrDate() in all my modules so that I can replace them with my custom function for the same purpose stated above.
Thanks.
Found that it's not possible to override.
So I used my own solution:
ok,
yes, I think a client variable can work, but will only work on device logic, if you have any business rules checked in the server, or you have any timers or processes that are date sensitive, they won't be able to reach that same client variable. If you have several users testing, they will not have a unified date.
Honestly I don't think this reply should be marked as solution. It only works cliƫnt side. Also it should be a foundation module not a core data module.
I disagree. Client side allows 2 different screen developers to unit test their screens independently, using different date as today's date for their own screen's functionality. This way, they won't step on each other's toes when using different dates for unit testing their functionality.
This is, of course, assuming that only the UI side is using CurrDate() in its conditions and queries for date based functionality. If the Server functionality is also affected by today's date then server side developers will need their own server based variable and function to test their side.
In the App I'm working on, only the UI screens behave differently based on current date so the solution I gave above works well for me to unit test.
You can unit test server actions also. My point is that the solution only covers client side, and not server side. But I am ok to disagree ;)
Hi Sanjay,
If I need this type of time travelling for testing purposes, I wrap the CurrDate() function into my own MyCurrDate() function, and don't use the CurrDate() directly.
This MyCurrDate() function can do something like looking at some setting, and give back a date based on that, or if nothing is set, ultimately by default give back the real corrDate(). You could also incorporate in that logic a safeguard for not using it in production, so there is no possibility for people to 'cook the books' by faking the timestamp of when something happened.
I think that is what you mean with 'my custom function', right ?
For the usage of CurrDate() you already have in, so you can replace them with that custom function, that will probably have to be done on a 'per module' base, by using the 'search in this module'.
Dorine