Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 75981 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java (-2 / +32 lines)
Lines 8-17 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Sebastian Davids: sdavids@gmx.de - see bug 25376
10
 *     Sebastian Davids: sdavids@gmx.de - see bug 25376
11
 *     Pramod Goyal: pramod.goyal@gmail.com - this is a bug - https://bugs.eclipse.org/75981
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.text.templates;
13
package org.eclipse.jface.text.templates;
13
14
15
import java.util.List;
16
import java.util.Locale;
17
14
import com.ibm.icu.text.DateFormat;
18
import com.ibm.icu.text.DateFormat;
19
import com.ibm.icu.text.SimpleDateFormat;
15
import com.ibm.icu.util.Calendar;
20
import com.ibm.icu.util.Calendar;
16
21
17
/**
22
/**
Lines 113-120 Link Here
113
		public Date() {
118
		public Date() {
114
			super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
119
			super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
115
		}
120
		}
116
		protected String resolve(TemplateContext context) {
121
117
			return DateFormat.getDateInstance().format(new java.util.Date());
122
		public void resolve(TemplateVariable variable, TemplateContext context) {
123
			List params= variable.getVariableType().getParams();
124
			DateFormat dateFormat = null;
125
			if (params.size() == 0)	{
126
				dateFormat= DateFormat.getDateInstance();
127
			}
128
			else if (params.size() == 1) {
129
				dateFormat= new SimpleDateFormat((String)params.get(0));
130
			}
131
			else if (params.size() == 2) {
132
				String localeString= (String)params.get(1);
133
				String[] localeParts= localeString.split("_");
134
				if (localeParts.length == 1) {
135
					dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0]));
136
				}
137
				else if (localeParts.length == 2) {
138
					dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0], localeParts[1]));
139
				}
140
			}
141
			if (dateFormat != null)	{
142
				variable.setValue(dateFormat.format(new java.util.Date()));
143
				variable.setUnambiguous(true);
144
			}
145
			else {
146
				super.resolve(variable, context);
147
			}
118
		}
148
		}
119
	}
149
	}
120
150
(-)a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties (-1 / +1 lines)
Lines 17-23 Link Here
17
# global variables
17
# global variables
18
GlobalVariables.variable.description.cursor=The cursor position after editing template variables
18
GlobalVariables.variable.description.cursor=The cursor position after editing template variables
19
GlobalVariables.variable.description.dollar=The dollar symbol
19
GlobalVariables.variable.description.dollar=The dollar symbol
20
GlobalVariables.variable.description.date=Current date
20
GlobalVariables.variable.description.date=Current date. Use ${id\:date(pattern [ , locale ])} to format the output. For valid patterns see java.text.SimpleDateFormat
21
GlobalVariables.variable.description.year=Current year
21
GlobalVariables.variable.description.year=Current year
22
GlobalVariables.variable.description.time=Current time
22
GlobalVariables.variable.description.time=Current time
23
GlobalVariables.variable.description.user=User name
23
GlobalVariables.variable.description.user=User name

Return to bug 75981