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 / +33 lines)
Lines 11-17 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jface.text.templates;
12
package org.eclipse.jface.text.templates;
13
13
14
import java.util.List;
15
import java.util.Locale;
16
14
import com.ibm.icu.text.DateFormat;
17
import com.ibm.icu.text.DateFormat;
18
import com.ibm.icu.text.SimpleDateFormat;
15
import com.ibm.icu.util.Calendar;
19
import com.ibm.icu.util.Calendar;
16
20
17
/**
21
/**
Lines 113-121 Link Here
113
		public Date() {
117
		public Date() {
114
			super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
118
			super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
115
		}
119
		}
116
		protected String resolve(TemplateContext context) {
120
117
			return DateFormat.getDateInstance().format(new java.util.Date());
121
		public void resolve(TemplateVariable variable, TemplateContext context) {
122
			List params= variable.getVariableType().getParams();
123
124
			Locale locale=Locale.getDefault();
125
			if (params.size()>=2) {
126
				String localeString= (String)params.get(1);
127
				String[] localeParts=localeString.split("_"); //$NON-NLS-1$
128
				if (localeParts.length==1) {
129
					locale= new Locale(localeParts[0]);
130
				} else if (localeParts.length==2) {
131
					locale= new Locale(localeParts[0], localeParts[1]);
132
				} else {
133
					throw new IllegalArgumentException(localeString);
134
				}
135
			}
136
137
			DateFormat format;
138
			if (params.size()>=1) {
139
				format= new SimpleDateFormat((String)params.get(0), locale);
140
			} else {
141
				format= DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
142
			}
143
144
			variable.setValue(format.format(new java.util.Date()));
118
		}
145
		}
146
147
148
149
119
	}
150
	}
120
151
121
	/**
152
	/**
(-)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.
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