Date formatting tag

I remember there is a tag where you can define the date formatting, like DD-MM-YYYY.
Is that documented somewhere?

Hi Nico,
the tag you mentioned is called format, here’s a short example on how to use it:

grok.data.getDemoTable('demog.csv').then((t) => {
    let view = grok.shell.addTableView(t);
    t.getCol('started').setTag('format', 'yyyy');
});

We will add an article about formatting to our Wiki soon :slight_smile: As for dates, you can use the following options to create your own format:

Years: ‘yy’, ‘yyyy’,
Months: ‘M’, ‘MM’, ‘MMM’, ‘MMMM’,
Days: ‘d’, ‘dd’, ‘ddd’, ‘dddd’,
Hours: ‘h’, ‘hh’, ‘H’, ‘HH’,
Minutes: ‘m’, ‘mm’,
Seconds: ‘s’, ‘ss’,
Milliseconds: ‘f’, ‘ff’, ‘fff’

We also have it on our samples:

Great, thanks a lot.
I assume this is one of the things which will also be persisted in the layout soon?

Exactly - actually we’ve already implemented that, format is persisted as part of the layout :slight_smile:

1 Like

We just reviewed this tag again and were wondering whether we could set a custom date formatting as a global default, because setting it for each date column in our large spreadsheets does not seem to be very efficient.

This is a good idea, but the way Datagrok works is a bit more sophisticated (I’m happy no one noticed it, it means it works as expected) :slight_smile: When working with the datetime columns, the platform automatically selects the best format fit for this particular dataset, and is not showing datetime parts like milliseconds, seconds, and hours/minutes if there is no need for it. This will make the implementation slightly more tricky, but it is doable. I’m guessing you might be interested in having a Swiss date format “dd.mm.yyyy” instead of the default US format, right?

While we are at it, we’ll also introduce default format for integers and floating point numbers.

And here’s a date formatting look-up table, just in case anyone needs it :wink:

2 Likes

Andrew, that’s certainly very useful.
Our requirement is mainly to have it as consistent through our apps as possible.
We are often using dd-MMMM-yyyy HH:mm:ss
Because this is neither US, nor EU specific.

So are you saying we cannot override the system default right now, other than just setting the tag for each date column?
What would work too, but just checking :slight_smile:

We’ve added the ability to specify global default formatting settings. If a format is specified on a column level, it takes precedence. Keep in mind that the platform automatically sets the most applicable format to the date time columns, so the mechanism might still need to be extended to accommodate for that.

image

image

Hi Andrew,
very nice, thanks!
Two follow-up questions:
1.

Keep in mind that the platform automatically sets the most applicable format to the date time columns, so the mechanism might still need to be extended to accommodate for that.

Does that mean that the global formatting will be overridden if the column “thinks” it should do better, even if nothing is explicitly set as formatting on the column?
2. How can we programmatically set this global data format?

Yes, you got it right. We hope to have both questions addressed today. Essentially, the platform should take into account the globally defined date format even when it thinks that it knows better (for instance, when it needs to visualize both dates and times, it will get the date from the settings). JS API is coming up as well.

ok, got it, thanks a lot!

We’ve exposed all properties of the Settings class, you can access them via the grok.shell.settings object:

grok.shell.settings.dateFormat = 'MMM';

Great, thanks a lot!