Those of you, who work with DeepSee, might have spotted, that when working with a date hierarchy, there are several functions, allowing you to select a time function for a given level. E.g. for extracting a year from a date/time property when building date hierarchy, you simply use Year function. similarly for month number, quarter and so on. Sometimes, you may wish to see the time - namely hour numbers. For this there is a HourNumber function available with DeepSee. Unfortunately, this function converts time into 12 hours format suffixed with AM/PM to indicate day part. This is not, however, much of use in certain parts of the world. You'd rather see hour numbers in 24 hour format.
Luckilly enough, the solution is easy, despite it requires some coding.
Let me guide you through the necessary steps in the following paragraphs.
First of all, the customization consist of creating a new Caché class. The class has to inherit from a % class and as you'd rather use this new class across the whole system, you need to - as a preliminary step - enable Write access to the CACHESYS database. I am not going to discuss details of this step, for details please refer to the documentation.
Now, let's start. Open the Studio (or Atelier, whichever you prefer) and navigate to %SYS namespace. Open %DeepSee.Time.HourNumber class and create a copy (Tools -> Copy Class...). Save the new class as e.g. %DeepSee.Time.HourNumber24.
Navigate to %KeyToValue function and modify the comment its last line. Now put this new line just below the commented one.
Compile the class.
Here we go, that's all we had to do! All you need to do now is just cleanup - make sure CACHELIB database is set to ReadOnly mode and go and test your new hour number function.
Now, if you look to DeepSee architect, and navigate to a combobox with Extract value with function label, you'll see something like this:
A new time function has appeared and is ready for use.
Hope you find this short article useful and it helps you!
Changing databases from read-only to read-write is described here:
https://community.intersystems.com/post/database-configuration
It can be done either in management portal or via cache object script.
You'll also need to modify %GetName method to return "HourNumber24".
Also must this new class be in %DeepSee package or can I write new class in user-space?
Probably not, as long as it inherits from correct parent. But then you need to make sure it's visible where it should (either via mapping or just copying to all namespaces needed)
As Daniel suggests, the class should extend %DeepSee.Time.AbstractLevel to be visible from Architect
Should the derived class be placed in %SYS? I would prefer the way to store the optional class in my Namespace or in %All if I want it be visible in all the namespaces. Unless my class will be erased with the next Caché update.
Some interesting things to note:
If you DO NOT put your custom class in the %DeepSee.Time package, it will not be visible through the Architect UI. Even if you do not include it in the %DeepSee.Time package, you will be able to modify your cube definition from Studio and specify your custom class. For example, I created the following class:
Class User.CustomTime1 Extends %DeepSee.Time.AbstractLevel
This custom class IS NOT visible in the Architect's "Extract value with function" drop down. However, I created a level with the following timeFunction value in my cube class from Studio:
timefunction="CustomTime1"
Manually entering this value will work and your custom time functions will be able to survive upgrades. If you do include your class in %DeepSee.Time, it will be listed in the Architect UI
Yes, %DeepSee.UI.Architect:GetTimeLevelClasses accepts only classes from %DeepSee.Time package.