Search in sources :

Example 1 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat in project error-prone by google.

the class MisusedWeekYearPositiveCases2 method testApplyPatternAndApplyLocalizedPattern.

void testApplyPatternAndApplyLocalizedPattern() {
    SimpleDateFormat sdf = new SimpleDateFormat();
    // BUG: Diagnostic contains: sdf.applyPattern("yyyy-MM-dd")
    sdf.applyPattern("YYYY-MM-dd");
    // BUG: Diagnostic contains:
    sdf.applyLocalizedPattern("YYYY-MM-dd");
}
Also used : SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat)

Example 2 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat in project eclipse.platform.text by eclipse.

the class GlobalTemplateVariablesDateTest method testComplexLocale.

@Test
public void testComplexLocale() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("France ${d:date('EEEE dd MMMM YYYY', 'fr_FR')} and Germany ${p:date('EEEE dd. MMMM YYYY', 'de_DE')}");
    fType.resolve(buffer, fContext);
    StringBuffer expected = new StringBuffer();
    expected.append("France ");
    expected.append(new SimpleDateFormat("EEEE dd MMMM YYYY", ULocale.FRANCE).format(new java.util.Date()));
    expected.append(" and Germany ");
    expected.append(new SimpleDateFormat("EEEE dd. MMMM YYYY", ULocale.GERMANY).format(new java.util.Date()));
    assertBufferStringAndVariables(expected.toString(), buffer);
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Test(org.junit.Test)

Example 3 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat in project eclipse.platform.text by eclipse.

the class GlobalTemplateVariablesDateTest method testOneParameter.

@Test
public void testOneParameter() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("This format ${d:date('dd MMM YYYY')} and not ${p:date('YYYY-MM-dd')}");
    fType.resolve(buffer, fContext);
    StringBuffer expected = new StringBuffer();
    expected.append("This format ");
    expected.append(new SimpleDateFormat("dd MMM YYYY").format(new java.util.Date()));
    expected.append(" and not ");
    expected.append(new SimpleDateFormat("YYYY-MM-dd").format(new java.util.Date()));
    assertBufferStringAndVariables(expected.toString(), buffer);
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat in project eclipse.platform.text by eclipse.

the class GlobalTemplateVariablesDateTest method testSimpleLocale.

@Test
public void testSimpleLocale() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("From ${d:date('dd MMM YYYY', 'fr')} to ${d}");
    fType.resolve(buffer, fContext);
    StringBuffer expected = new StringBuffer();
    expected.append("From ");
    expected.append(new SimpleDateFormat("dd MMM YYYY", ULocale.FRENCH).format(new java.util.Date()));
    expected.append(" to ");
    expected.append(new SimpleDateFormat("dd MMM YYYY", ULocale.FRENCH).format(new java.util.Date()));
    assertBufferStringAndVariables(expected.toString(), buffer);
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Test(org.junit.Test)

Example 5 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat in project eclipse.platform.text by eclipse.

the class GlobalTemplateVariablesDateTest method testInvalidLocale.

@Test
public void testInvalidLocale() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("Today is ${d:date('YYYY-MM-dd', 'this_invalid_locale')}!");
    fType.resolve(buffer, fContext);
    StringBuffer expected = new StringBuffer();
    expected.append("Today is ");
    expected.append(new SimpleDateFormat("YYYY-MM-dd", new ULocale("this_invalid_locale")).format(new java.util.Date()));
    expected.append("!");
    assertBufferStringAndVariables(expected.toString(), buffer);
}
Also used : ULocale(com.ibm.icu.util.ULocale) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)16 Date (java.util.Date)8 DateFormat (com.ibm.icu.text.DateFormat)4 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)4 Test (org.junit.Test)4 Calendar (java.util.Calendar)3 ULocale (com.ibm.icu.util.ULocale)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 Locale (java.util.Locale)2 SequenceFile (org.apache.hadoop.io.SequenceFile)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Skeleton (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.Skeleton)1 Context (com.github.jknack.handlebars.Context)1 Handlebars (com.github.jknack.handlebars.Handlebars)1 Template (com.github.jknack.handlebars.Template)1 FileTemplateLoader (com.github.jknack.handlebars.io.FileTemplateLoader)1