Package com.ibm.icu.text

Examples of com.ibm.icu.text.DateFormat


    }

    {
        // limits
        JapaneseCalendar cal = new JapaneseCalendar();
        DateFormat fmt = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, Locale.ENGLISH);

        cal.set(Calendar.ERA, JapaneseCalendar.MEIJI);
        logln("date: " + cal.getTime());
        logln("min era: " + cal.getMinimum(Calendar.ERA));
        logln("min year: " + cal.getMinimum(Calendar.YEAR));
        cal.set(Calendar.YEAR, cal.getActualMaximum(Calendar.YEAR));
        logln("date: " + fmt.format(cal.getTime()));
        cal.add(Calendar.YEAR, 1);
        logln("date: " + fmt.format(cal.getTime()));
    }

    {
        // data
        JapaneseCalendar cal = new JapaneseCalendar(1868, Calendar.JANUARY, 1);
        Date time = cal.getTime();

        String[] calendarLocales = {
        "en", "ja_JP"
        };

        String[] formatLocales = {
        "en", "ja"
        };
        for (int i = 0; i < calendarLocales.length; ++i) {
            String calLocName = calendarLocales[i];
            Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
            cal = new JapaneseCalendar(calLocale);

            for (int j = 0; j < formatLocales.length; ++j) {
                String locName = formatLocales[j];
                Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
                DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
                logln(calLocName + "/" + locName + " --> " + format.format(time));
            }
        }
    }
    }
View Full Code Here


   
    public void Test3860()
    {
        ULocale loc = new ULocale("ja_JP@calendar=japanese");
        Calendar cal = new JapaneseCalendar(loc);
        DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
        DateFormat format = cal.getDateTimeFormat(0,0,loc);
        ((SimpleDateFormat)format).applyPattern("y.M.d")// Note: just 'y' doesn't work here.
        ParsePosition pos = new ParsePosition(0);
        Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession.  Jan 1, 1H wouldn't work  because it is actually showa 64
        String inEn = enjformat.format(aDate);

        cal.clear();
        cal.setTime(aDate);
        int gotYear = cal.get(Calendar.YEAR);
View Full Code Here

        }
    }

    public void Test5345parse() {
        // Test parse with incomplete information
        DateFormat fmt2= DateFormat.getDateInstance(); //DateFormat.LONG, Locale.US);
        JapaneseCalendar c = new JapaneseCalendar(TimeZone.getDefault(), new ULocale("en_US"));
        SimpleDateFormat fmt = (SimpleDateFormat)c.getDateTimeFormat(1,1,new ULocale("en_US@calendar=japanese"));
        fmt.applyPattern("G y");
        logln("fmt's locale = " + fmt.getLocale(ULocale.ACTUAL_LOCALE));
        //SimpleDateFormat fmt = new SimpleDateFormat("G y", new Locale("en_US@calendar=japanese"));
        long aDateLong = -3197120400000L
            + 3600000L; // compensate for DST
        Date aDate = new Date(aDateLong); //08 Sept 1868
        logln("aDate: " + aDate.toString() +", from " + aDateLong);
        String str;
        str = fmt2.format(aDate);
        logln("Test Date: " + str);
        str = fmt.format(aDate);
        logln("as Japanese Calendar: " + str);
        String expected = "Meiji 1";
        if(!str.equals(expected)) {
View Full Code Here

        for (int day = 1; day < 3; ++day) {
            cal.set(1, 0, day);
            logln("[" + day + "] " + (cal.getTimeInMillis()/MILLIS_IN_DAY));
        }

        DateFormat fmt = cal.getDateTimeFormat(DateFormat.LONG, 0, Locale.getDefault());

        logln("\nswitchover in 1582");
        cal.set(1582, 9, 4);
        logln(fmt.format(cal));
        cal.add(Calendar.DATE, 1);
        logln(fmt.format(cal));
        cal.set(Calendar.JULIAN_DAY, 1721426);
        logln(fmt.format(cal));

        logln("\nlate switchover - proleptic Julian");
        cal.set(1582, 9, 4);
        cal.setGregorianChange(new Date(Long.MAX_VALUE));
        logln(fmt.format(cal));
        cal.add(Calendar.DATE, 1);
        logln(fmt.format(cal));
        cal.set(Calendar.JULIAN_DAY, 1721426);
        logln(fmt.format(cal));

        logln("\nearly switchover - proleptic Gregorian");
        cal.set(1582, 9, 4);
        cal.setGregorianChange(new Date(Long.MIN_VALUE));
        logln(fmt.format(cal));
        cal.add(Calendar.DATE, 1);
        logln(fmt.format(cal));
        cal.set(Calendar.JULIAN_DAY, 1721426);
        logln(fmt.format(cal));
    }
View Full Code Here

                cal = new EthiopicCalendar(calLocale);

                for (int j = 0; j < formatLocales.length; ++j) {
                    String locName = formatLocales[j];
                    Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
                    DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
                    logln(calLocName + "/" + locName + " --> " + format.format(time));
                }
            }
        }
    }
View Full Code Here

    public void TestDateFormat() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        String pattern;
        DateFormat df;

        // Set unsupported locale - ach
        logln("Set locale - ach");
        gp.setLocale(new ULocale("ach"));

        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        // root pattern must be used
        if (!pattern.equals("yyyy-MM-dd")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: yyyy-MM-dd");
        }

        // Set locale - fr, fr_CA, fr_FR
        ArrayList lcls = new ArrayList(3);
        lcls.add(new ULocale("fr"));
        lcls.add(new ULocale("fr_CA"));
        lcls.add(new ULocale("fr_FR"));
        logln("Set locales - fr, fr_CA, fr_FR");
        gp.setLocales(lcls);
        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        // fr_CA pattern must be used
        if (!pattern.equals("yy-MM-dd")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: yy-MM-dd");
        }


        // Set locale - en_GB
        logln("Set locale - en_GB");
        gp.setLocale(new ULocale("en_GB"));
       
        // Date - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("EEEE, d MMMM y")) {
            errln("FAIL: FULL date pattern is " + pattern + " Expected: EEEE, d MMMM y");
        }

        // Date - long
        df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("d MMMM y")) {
            errln("FAIL: LONG date pattern is " + pattern + " Expected: d MMMM y");
        }

        // Date - medium
        df = gp.getDateFormat(GlobalizationPreferences.DF_MEDIUM, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("d MMM y")) {
            errln("FAIL: MEDIUM date pattern is " + pattern + " Expected: d MMM y");
        }

        // Date - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("dd/MM/yyyy")) {
            errln("FAIL: SHORT date pattern is " + pattern + " Expected: dd/MM/yyyy");
        }

        // Time - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_FULL);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss zzzz")) {
            errln("FAIL: FULL time pattern is " + pattern + " Expected: HH:mm:ss zzzz");
        }

        // Time - long
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_LONG);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss z")) {
            errln("FAIL: LONG time pattern is " + pattern + " Expected: HH:mm:ss z");
        }

        // Time - medium
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_MEDIUM);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm:ss")) {
            errln("FAIL: MEDIUM time pattern is " + pattern + " Expected: HH:mm:ss");
        }

        // Time - short
        df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_SHORT);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("HH:mm")) {
            errln("FAIL: SHORT time pattern is " + pattern + " Expected: HH:mm");
        }

        // Date/Time - full
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_FULL);
        pattern = ((SimpleDateFormat)df).toPattern();
        if (!pattern.equals("EEEE, d MMMM y HH:mm:ss zzzz")) {
            errln("FAIL: FULL date/time pattern is " + pattern + " Expected: EEEE, d MMMM y HH:mm:ss zzzz");
        }

        // Invalid style
        boolean illegalArg = false;
        try {
            df = gp.getDateFormat(-1, GlobalizationPreferences.DF_NONE);
        } catch (IllegalArgumentException iae) {
            logln("Illegal date style -1");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle -1");
        }

        illegalArg = false;
        try {
            df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_NONE);
        } catch (IllegalArgumentException iae) {
            logln("Illegal style - dateStyle:DF_NONE / timeStyle:DF_NONE");
            illegalArg = true;
        }
        if (!illegalArg) {
            errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle:DF_NONE/timeStyle:DF_NONE");
        }

        // Set explicit time zone
        logln("Set timezone - America/Sao_Paulo");
        TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo");
        gp.setTimeZone(tz);
        df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_MEDIUM);
        String tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Set explicit calendar
        logln("Set calendar - japanese");
        Calendar jcal = new JapaneseCalendar();
        jcal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
        gp.setCalendar(jcal);
        df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_SHORT);
        Calendar dfCal = df.getCalendar();
        if (!(dfCal instanceof JapaneseCalendar)) {
            errln("FAIL: The DateFormat instance must use Japanese calendar");
        }
        // TimeZone must be still America/Sao_Paulo
        tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Set explicit DateFormat
        logln("Set explicit date format - full date");
        DateFormat customFD = DateFormat.getDateInstance(new IslamicCalendar(), DateFormat.FULL, new ULocale("ar_SA"));
        customFD.setTimeZone(TimeZone.getTimeZone("Asia/Riyadh"));
        gp.setDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE, customFD);
        df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
        dfCal = df.getCalendar();
        if (!(dfCal instanceof IslamicCalendar)) {
            errln("FAIL: The DateFormat instance must use Islamic calendar");
        }
        // TimeZone in the custom DateFormat is overridden by GP's timezone setting
        tzid = df.getTimeZone().getID();
        if (!tzid.equals("America/Sao_Paulo")) {
            errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
        }

        // Freeze
        logln("Freeze this object");
        gp.freeze();
        DateFormat customLD = DateFormat.getDateInstance(new BuddhistCalendar(), DateFormat.LONG, new ULocale("th"));
        customLD.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok"));
        boolean isFrozen = false;
        try {
            gp.setDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE, customLD);
        } catch (UnsupportedOperationException uoe) {
            logln("setDateFormat is blocked");
View Full Code Here

     * Test method for 'com.ibm.icu.util.Calendar.getDateTimeFormat(int, int, Locale)'
     */
    public void testGetDateTimeFormatIntIntLocale() {
        Calendar cal = Calendar.getInstance();
        cal.set(1990, 8, 16, 20, 3);
        DateFormat df = cal.getDateTimeFormat(DateFormat.LONG, DateFormat.SHORT, Locale.US);
        assertEquals("September 16, 1990 8:03 PM", df.format(cal));
    }
View Full Code Here

     * Test method for 'com.ibm.icu.util.Calendar.getDateTimeFormat(int, int, ULocale)'
     */
    public void testGetDateTimeFormatIntIntULocale() {
        Calendar cal = Calendar.getInstance();
        cal.set(1990, 8, 16, 20, 3);
        DateFormat df = cal.getDateTimeFormat(DateFormat.LONG, DateFormat.SHORT, ULocale.US);
        assertEquals("September 16, 1990 8:03 PM", df.format(cal));
    }
View Full Code Here

    public void testGetFormats() {
        MessageFormat mf = new MessageFormat(pattern, Locale.US);
        Format[] formats = mf.getFormats();
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
        assertEquals(formats[0], nf);
        DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US);
        assertEquals(formats[1], tf);
        DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
        assertEquals(formats[2], df);
    }
View Full Code Here

                                ((ListOfCharValueNode)sourceVN).getStringValue() :
                                ((LiteralValueNode)sourceVN).getStringValue();

            if (handlerClass.equals(RelativeDateValueNode.class)) {

                DateFormat dateFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, -1);

                try {

                    newValue = dateFormat.parse(stringVal);

                } catch (ParseException pe) {

                    // Okay, can't parse.  Don't transform.
                }

            } else if (handlerClass.equals(RelativeTimeValueNode.class)) {

                DateFormat timeFormat = RelativeTemporalValueNode.getDateFormat(-1, DateFormat.MEDIUM);

                try {

                    newValue = timeFormat.parse(stringVal);

                } catch (ParseException pe) {

                    // Okay, can't parse.  Don't transform.
                }

            } else if (handlerClass.equals(RelativeDateTimeValueNode.class)) {

                DateFormat dateTimeFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, DateFormat.MEDIUM);

                try {

                    newValue = dateTimeFormat.parse(stringVal);

                } catch (ParseException pe) {

                    // Okay, can't parse.  Don't transform.
                }
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.DateFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.