Format Date localized

Hi, 

I want to format a date in a workflow. For that I am using the format function of the date-time module. Now I have noticed that the text parts of the date do not get localized to the system language of YouTrack.

E.g. dateTime.format(new Date("2025-09-16"), "EEE, d. MMM YYYY", "Etc/GMT") yields Tue, 16. Sep 2025 even if the language is set to German. I would expect Di., 16. Sep. 2025.

Is there some way to control this or is this a bug?

0
6 comments
Official comment

Hi,

I'm Sergey from the YouTrack team.

Each user can set a preferred date format in the user profile settings → Date format. 

Hi,

I think there was a misunderstanding. I already have a format to pass to the function. I was wondering why the text parts of the date are not translated. For example, 'Tue' is used instead of 'Di.' when the language is set to German.

0

Hi!

Please share a screenshot where you see the incorrect date format. As I mentioned earlier, the date format displayed in the UI isn't controlled by how you specify it in the workflow, as it actually depends on the date format setting in your user profile.

Either way, please share a screenshot and I'll provide further details.

0

Hi,

i have simplified my use case to the following code example where i'm using an action workflow to write a comment under the selected article. 

const entities = require('@jetbrains/youtrack-scripting-api/entities.js');
const dateTime = require("@jetbrains/youtrack-scripting-api/date-time")

exports.rule = entities.Issue.action({
  title: 'Test',
  userInput: null,
  command: 'test',
  guard: (ctx) => true,
  action: (ctx) => {
   ctx.issue.addComment("Das Datum wird formatiert als: " + dateTime.format(new Date("2025-05-16"), "EEE, d. MMM. YYYY", "Etc/GMT"));
  },
  requirements: {}
});

This results on execution in the creation of the following comment:

And i have the following settings in my user profile:

The comment which got produced does not seem to use the date format of the user profile but rather the date format which I have passed to the function. That is what i would expect according to the documentation

My problem is with the text parts of this date like ‘Fri’ and ‘May’. I have chosen German as the display language in my user profile and in the general settings but the text of the date does not get translated.

I hope this example helps to understand my problem.

0

Thanks for the clarification. Now everything is clear.

The dateTime.format() function doesn't support locale configuration for translating text parts like day and month names. The text portions (like "Fri" and "May") are always rendered in English, regardless of your YouTrack profile language settings.

Here are a couple of approaches to work around this limitation:

Manual Translation Approach

Create your own translation arrays and format function:

const DAYS_DE = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
const MONTHS_DE = ['Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni', 'Juli', 'Aug.', 'Sep.', 'Okt.', 'Nov.', 'Dez.'];

function formatDateGerman(date) {
  const d = new Date(date);
  return `${DAYS_DE[d.getDay()]}, ${d.getDate()}. ${MONTHS_DE[d.getMonth()]} ${d.getFullYear()}`;
}

Numeric Format Alternative

Use a fully numeric format to avoid locale issues entirely:

dateTime.format(new Date("2025-05-16"), "dd.MM.yyyy", "Etc/GMT")
// Output: "16.05.2025"
0

Alright, thank you for answer. I will probably use a full numeric format then

0

Please sign in to leave a comment.