Displaying timestamp in Workshop using year only

Hello,

I would like to display a Timestamp variable in a Workshop metric card with date/time formatting enabled such that only the year is shown. I can almost do this using the “Custom” option under “Date and time formatting”, but it does not actually let me specify a custom format like “yyyy”:

How can I configure the date and time format so it displays the year only?

Hi @haavard, seconding your desire for more configurable date/time displays in workshop. In the meantime, I would author a typescript function that returns the year as a string.

Assuming you are collecting a timestamp property from an object, you can pass in the object to your function and return the year:

import { Function } from "@foundry/functions-api";
import { yourObjectApi } from "@foundry/ontology-api";

export class MyFunctions {
    @Function()
    public getYearFromTimestampProperty(yourObject: yourObjectApi): string {
        return yourObject.timestampProperty!.getYear().toString()
    }
}

Alternatively, you can pass in the last value date variable you’ve defined in Workshop and return the year in the function:

import { Function, Timestamp } from "@foundry/functions-api";

export class MyFunctions {
    @Function()
    public getYearFromTimestamp(timestamp: Timestamp): string {
        return timestamp.getYear().toString()
    }
}

Then, in the metric card config, select String as the “Secondary Metric Value Type”, select your function, and configure the inputs. Hope this helps!

1 Like