Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 235875 Details for
Bug 75981
[templates][preferences] Allow to specify format of date variable in templates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix as per Dani's comment
Adding-support-for-date-format-and-locale.patch (text/plain), 3.13 KB, created by
Pramod Goyal
on 2013-09-26 23:51:05 EDT
(
hide
)
Description:
Fix as per Dani's comment
Filename:
MIME Type:
Creator:
Pramod Goyal
Created:
2013-09-26 23:51:05 EDT
Size:
3.13 KB
patch
obsolete
>diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java >index 19f27f6..d0ee05e 100644 >--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java >+++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java >@@ -8,10 +8,15 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Sebastian Davids: sdavids@gmx.de - see bug 25376 >+ * Pramod Goyal: pramod.goyal@gmail.com - this is a bug - https://bugs.eclipse.org/75981 > *******************************************************************************/ > package org.eclipse.jface.text.templates; > >+import java.util.List; >+import java.util.Locale; >+ > import com.ibm.icu.text.DateFormat; >+import com.ibm.icu.text.SimpleDateFormat; > import com.ibm.icu.util.Calendar; > > /** >@@ -113,8 +118,33 @@ > public Date() { > super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ > } >- protected String resolve(TemplateContext context) { >- return DateFormat.getDateInstance().format(new java.util.Date()); >+ >+ public void resolve(TemplateVariable variable, TemplateContext context) { >+ List params= variable.getVariableType().getParams(); >+ DateFormat dateFormat = null; >+ if (params.size() == 0) { >+ dateFormat= DateFormat.getDateInstance(); >+ } >+ else if (params.size() == 1) { >+ dateFormat= new SimpleDateFormat((String)params.get(0)); >+ } >+ else if (params.size() == 2) { >+ String localeString= (String)params.get(1); >+ String[] localeParts= localeString.split("_"); >+ if (localeParts.length == 1) { >+ dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0])); >+ } >+ else if (localeParts.length == 2) { >+ dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0], localeParts[1])); >+ } >+ } >+ if (dateFormat != null) { >+ variable.setValue(dateFormat.format(new java.util.Date())); >+ variable.setUnambiguous(true); >+ } >+ else { >+ super.resolve(variable, context); >+ } > } > } > >diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties >index a2549f0..5474ef4 100644 >--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties >+++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties >@@ -17,7 +17,7 @@ > # global variables > GlobalVariables.variable.description.cursor=The cursor position after editing template variables > GlobalVariables.variable.description.dollar=The dollar symbol >-GlobalVariables.variable.description.date=Current date >+GlobalVariables.variable.description.date=Current date. Use ${id\:date(pattern [ , locale ])} to format the output. For valid patterns see java.text.SimpleDateFormat > GlobalVariables.variable.description.year=Current year > GlobalVariables.variable.description.time=Current time > GlobalVariables.variable.description.user=User name
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 75981
:
98429
|
213533
| 235875 |
235894