Hello community!
I have found some examples of how to format dates in a way that it aligns with the preferred date format of users in different countries. The classic example is the one comparing the order of day and month in the US versus in Europe. If we are tracking user locale as an attribute, we can do date formatting with liquid variables in the sql or html parameters of a formatted time dimension: https://www.googlecloudcommunity.com/gc/Technical-Tips-Tricks/Advanced-LookML-Liquid-Use-Cases/ta-p/....
Since we have many user locales each with its own preferred date format, this means we are going to need a very long case statement to generate a localised date format. That's okay if we were only expected to write it once, but the point here is that we actually want every single exposed date to be localised. Soon we start writing the same logic in multiple places. That's breaks the DRY principle of not repeat yourself, makes us prone to mistakes and makes it a hassle to add more preferred date formats or edit the existing logic overall.
Thus the question: is there a way to save and re-use the logic behind the preferred time format across the project?
Thank you,
Daniel
Hello Daniel,
Re-summarizing to confirm my understanding: You are have complex logic you want to apply on many date fields. You are looking for a way to define that logic only once, so it is easier to maintain.
One approach I have seen success with for this is to define your logic in Constants (https://cloud.google.com/looker/docs/reference/param-manifest-constant), and then your logic can be applied with a simpler reference to the constant throughout the model.
For example, if manipulating format in HTML, you could use define and then use a constant something like this:
Thanks for the suggestion, Kevin. I was not aware of constants in Looker. Will take a look.