Bug 105802 - [preference] Add option to specifiy format of ${date} and ${time} variables
Summary: [preference] Add option to specifiy format of ${date} and ${time} variables
Status: RESOLVED DUPLICATE of bug 75981
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P4 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2005-08-02 11:06 EDT by Christian Spreuer CLA
Modified: 2006-08-15 03:46 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Spreuer CLA 2005-08-02 11:06:38 EDT
The locale used to format the variables of the Java Code Templates is always 
the locale of the current machine and can not be overridden.
A possible workaround on Unix could be to set environment variables (LC?) in 
the batch which you use to start eclipse. There is no such environment variable 
on Windows AFAIK.

This is an issue for international projects where development is done all over 
the world, and thus the date which gets inserted into the comments is formatted 
differently depending on the developer who did the specific update.

Same problem, different company:
http://dev.eclipse.org/newslists/news.eclipse.platform/msg25683.html

Eclipse developers do not notice this as they never put the current date into 
the sources (of Eclipse itself, AFAIK). In fact, ${date} and ${time} could be a 
nice feature, but is currently not usable for us.

Thank you for the whole thing, nevertheless - Eclipse is great.
Comment 1 Tom Hofmann CLA 2005-08-04 04:48:34 EDT
Implementing this would need parameterizable template variables.

You could then have a template such as this:

  ${date,en_US}

or

  ${date,en_US,yyyy/mm/dd}

See also bug 10694 on a related problem (type constraints for template variables).
Comment 2 Dani Megert CLA 2005-08-04 06:10:18 EDT
There's an Eclipse command line argument for this: -nl <locale>
Comment 3 Christian Spreuer CLA 2005-08-04 09:17:02 EDT
Daniel Megert, you are right - according to what I have written, the command 
line argument -nl actually solves the problem; all developers can use a common 
locale and thus the date will always be formatted identically.

But what I have meant is that I know no way to specify that Eclipse should 
format a date as yyyy/mm/dd - except by changing the locale to China/Chinese, 
and this may have unwanted other effects as I can not read Chinese ;-).
Java is ignoring the Windows XP settings, where I specified that my Locale is 
German but nevertheless dates have to be formatted as yyyy/MM/dd.

I assume the proposal from Tom P. Eicher ${date,en_US,"yyyy/mm/dd"} could be 
too complicated to implement as general and clean solution. At least it needs 
much documentation which parameters can be put on what variable.

I am thinking in the direction that the Preferences for Java Code Templates 
could get a third sub-tree "Variables" in addition to "Comments" and "Code", 
where it would be possible e.g. to specify how ${todo} should look like, the 
full ${user} name (which e.g. for me differs significantly from the login 
name), and, ultimately, the format strings for date and time.
Comment 4 Dani Megert CLA 2005-08-04 09:39:53 EDT
>and this may have unwanted other effects as I can not read Chinese ;-).
Assuming you installed the language pack you could simply remove those language
that you do not understand :-)

>${todo} should look like
This stands for the default todo tag - not sure what you would want to configure
here.

>full ${user} name (
This can be specified when starting Eclipse - no plans to add this.

We could add preferences for the data and time format variables.
Comment 5 Alex Blewitt CLA 2005-08-24 09:04:28 EDT
Being able to define the order of ${date} and ${time} is useful as a preference,
because sometimes code is written by people in different geographical locations
and there may be a coding standard that all dates are represented as ISO
standard (2005-12-31).

The 'best' solution would be to have a preference that is globally sharable
without having to change individual PCs time/date settings or invoke with
special arguments; after all, that's exactly what happens with other coding
standards (such as indentation).

If that's too difficult to implement, it could also be solved with the provision
of ${day} ${month} ${year} variables, and thus people can hard-code templates to
whatever format they want. There might however be arguments as to whether the
values should be zero-prefixed or words instead of numbers, but in the spirit of
internationalisation (and because it's easier) I think numbers would satisfy. I
would suggest that a zero-prefixed 24h is used by default in case external tools
need to be able to parse on position instead of delimiter.
Comment 6 Dani Megert CLA 2006-08-15 03:46:42 EDT

*** This bug has been marked as a duplicate of 75981 ***