Exemplo n.º 1
0
  public static void main(String[] args) {
    String str1 = "hello";
    String str2 = new String("hello");
    System.out.println(str1.equals(str2));
    System.out.println(str1.intern() == str2.intern());

    Date now = new Date();

    Calendar calendar = Calendar.getInstance();
    System.out.println(calendar.getMinimalDaysInFirstWeek());
    //		calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(now);

    calendar.add(Calendar.DATE, 144);
    System.out.println(calendar.getTime());
    String burepayDay = new SimpleDateFormat("YYYYÄêMMÔÂddÈÕ").format(calendar.getTime());

    System.out.println(calendar.getTime().toLocaleString());
    System.out.println(burepayDay);

    System.out.println(calendar.getWeeksInWeekYear());

    String str = "hjjk";
    System.out.println(str.substring(0, 4));
  }
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getMinimalDaysInFirstWeek",
     args = {})
 public void test_getMinimalDaysInFirstWeek() {
   Locale[] requiredLocales = {Locale.US, Locale.FRANCE};
   if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
     // locale dependent test, bug 1943269
     return;
   }
   Calendar cal = Calendar.getInstance();
   assertTrue(cal.getMinimalDaysInFirstWeek() == 1);
   Locale.setDefault(Locale.FRANCE);
   cal = Calendar.getInstance();
   assertTrue(cal.getMinimalDaysInFirstWeek() == 4);
   Locale.setDefault(Locale.US);
 }
Exemplo n.º 3
0
 public void write(Kryo kryo, Output output, Calendar object) {
   timeZoneSerializer.write(kryo, output, object.getTimeZone()); // can't be null
   output.writeLong(object.getTimeInMillis(), true);
   output.writeBoolean(object.isLenient());
   output.writeInt(object.getFirstDayOfWeek(), true);
   output.writeInt(object.getMinimalDaysInFirstWeek(), true);
   if (object instanceof GregorianCalendar)
     output.writeLong(((GregorianCalendar) object).getGregorianChange().getTime(), false);
   else output.writeLong(DEFAULT_GREGORIAN_CUTOVER, false);
 }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "setMinimalDaysInFirstWeek",
      args = {int.class})
  public void test_setMinimalDaysInFirstWeekI() {
    Calendar cal = Calendar.getInstance();

    for (int i = 0; i < 10; i++) {
      cal.setMinimalDaysInFirstWeek(i);
      assertEquals(i, cal.getMinimalDaysInFirstWeek());
    }
    cal.setLenient(false);
    cal.setMinimalDaysInFirstWeek(10);
    cal.setMinimalDaysInFirstWeek(-10);
  }
Exemplo n.º 5
0
  private static DateTimeFormatSymbols createInfo(Locale locale) {
    DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
    DateTimeFormatter.checkNotNull(oldSymbols, "Symbols to convert must not be null");
    char zeroDigit = oldSymbols.getZeroDigit();
    char positiveSign = '+';
    char negativeSign = oldSymbols.getMinusSign();
    char decimalSeparator = oldSymbols.getDecimalSeparator();

    Calendar cal = Calendar.getInstance(locale);
    int calFDoW = cal.getFirstDayOfWeek();
    DayOfWeek firstDayOfWeek = (calFDoW == 1 ? DayOfWeek.SUNDAY : DayOfWeek.of(calFDoW - 1));
    int minDaysInFirstWeek = cal.getMinimalDaysInFirstWeek();

    return new DateTimeFormatSymbols(
        locale,
        zeroDigit,
        positiveSign,
        negativeSign,
        decimalSeparator,
        firstDayOfWeek,
        minDaysInFirstWeek);
  }
Exemplo n.º 6
0
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    IForm form = getForm(cycle);

    String name = form.getElementId(this);

    String format = getFormat();

    if (format == null) format = "dd MMM yyyy";

    SimpleDateFormat formatter = new SimpleDateFormat(format, getPage().getLocale());

    boolean disabled = isDisabled();

    if (!cycle.isRewinding()) {
      Body body = Body.get(cycle);

      if (body == null)
        throw new ApplicationRuntimeException(
            Tapestry.format("must-be-contained-by-body", "DatePicker"), this, null, null);

      Locale locale = getPage().getLocale();
      DateFormatSymbols dfs = new DateFormatSymbols(locale);
      Calendar cal = Calendar.getInstance(locale);

      Date value = getValue();

      Map symbols = new HashMap();

      symbols.put(SYM_NAME, name);
      symbols.put(SYM_FORMAT, format);
      symbols.put(SYM_INCL_WEEK, getIncludeWeek() ? Boolean.TRUE : Boolean.FALSE);

      symbols.put(SYM_MONTHNAMES, makeStringList(dfs.getMonths(), 0, 12));
      symbols.put(SYM_SHORT_MONTHNAMES, makeStringList(dfs.getShortMonths(), 0, 12));
      symbols.put(SYM_WEEKDAYNAMES, makeStringList(dfs.getWeekdays(), 1, 8));
      symbols.put(SYM_SHORT_WEEKDAYNAMES, makeStringList(dfs.getShortWeekdays(), 1, 8));
      symbols.put(SYM_FIRSTDAYINWEEK, new Integer(cal.getFirstDayOfWeek() - 1));
      symbols.put(SYM_MINDAYSINFIRSTWEEK, new Integer(cal.getMinimalDaysInFirstWeek()));
      symbols.put(SYM_FORMNAME, form.getName());
      symbols.put(SYM_VALUE, value);

      _script.execute(cycle, body, symbols);

      writer.beginEmpty("input");
      writer.attribute("type", "text");
      writer.attribute("name", name);
      writer.attribute("title", formatter.toLocalizedPattern());

      if (value != null) writer.attribute("value", formatter.format(value));

      if (disabled) writer.attribute("disabled", "disabled");

      renderInformalParameters(writer, cycle);

      writer.printRaw("&nbsp;");

      if (!disabled) {
        writer.begin("a");
        writer.attribute("href", (String) symbols.get(SYM_BUTTONONCLICKHANDLER));
      }

      IAsset icon = getIcon();

      writer.beginEmpty("img");
      writer.attribute("src", icon.buildURL(cycle));
      writer.attribute("border", 0);

      if (!disabled) writer.end(); // <a>
    }

    if (form.isRewinding()) {
      if (disabled) return;

      String textValue = cycle.getRequestContext().getParameter(name);

      if (Tapestry.isBlank(textValue)) return;

      try {
        Date value = formatter.parse(textValue);

        setValue(value);
      } catch (ParseException ex) {
      }
    }
  }
Exemplo n.º 7
0
  static String describeLocale(String name) {
    final StringBuilder result = new StringBuilder();
    result.append("<html>");

    final Locale locale = localeByName(name);

    result.append("<p>");
    append(result, "Display Name", locale.getDisplayName());
    append(result, "Localized Display Name", locale.getDisplayName(locale));

    if (locale.getLanguage().length() > 0) {
      String iso3Language = "(not available)";
      try {
        iso3Language = locale.getISO3Language();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Language", locale.getDisplayLanguage());
      append(result, "Localized Display Language", locale.getDisplayLanguage(locale));
      append(result, "2-Letter Language Code", locale.getLanguage());
      append(result, "3-Letter Language Code", iso3Language);
    }
    if (locale.getCountry().length() > 0) {
      String iso3Country = "(not available)";
      try {
        iso3Country = locale.getISO3Country();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Country", locale.getDisplayCountry());
      append(result, "Localized Display Country", locale.getDisplayCountry(locale));
      append(result, "2-Letter Country Code", locale.getCountry());
      append(result, "3-Letter Country Code", iso3Country);
    }
    if (locale.getVariant().length() > 0) {
      result.append("<p>");
      append(result, "Display Variant", locale.getDisplayVariant());
      append(result, "Localized Display Variant", locale.getDisplayVariant(locale));
      append(result, "Variant Code", locale.getVariant());
    }

    result.append("<p><b>Number Formatting</b>");
    describeNumberFormat(result, "Decimal", NumberFormat.getInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Integer", NumberFormat.getIntegerInstance(locale), 1234, -1234);
    describeNumberFormat(
        result, "Currency", NumberFormat.getCurrencyInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Percent", NumberFormat.getPercentInstance(locale), 12.3);

    boolean hasLocaleData = hasLocaleData();

    if (!hasLocaleData) {
      result.append("<p><b>Decimal Format Symbols</b>");
      NumberFormat nf = NumberFormat.getInstance(locale);
      if (nf instanceof DecimalFormat) {
        describeDecimalFormatSymbols(result, ((DecimalFormat) nf).getDecimalFormatSymbols());
      } else {
        result.append("(Didn't expect " + nf.getClass() + ".)");
      }
    }

    Date now =
        new Date(); // FIXME: it might be more useful to always show a time in the afternoon, to
    // make 24-hour patterns more obvious.
    result.append("<p><b>Date/Time Formatting</b>");
    describeDateFormat(
        result, "Full Date", DateFormat.getDateInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Date", DateFormat.getDateInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Date", DateFormat.getDateInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Date", DateFormat.getDateInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result, "Full Time", DateFormat.getTimeInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Time", DateFormat.getTimeInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Time", DateFormat.getTimeInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Time", DateFormat.getTimeInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result,
        "Full Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale),
        now);
    describeDateFormat(
        result,
        "Long Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale),
        now);
    describeDateFormat(
        result,
        "Medium Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale),
        now);
    describeDateFormat(
        result,
        "Short Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale),
        now);

    if (!hasLocaleData) {
      result.append("<p><b>Date Format Symbols</b><p>");
      DateFormat edf = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
      DateFormatSymbols edfs = ((SimpleDateFormat) edf).getDateFormatSymbols();
      DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale);
      DateFormatSymbols dfs = ((SimpleDateFormat) df).getDateFormatSymbols();
      append(result, "Local Pattern Chars", dfs.getLocalPatternChars());
      append(result, "Am/pm", Arrays.toString(dfs.getAmPmStrings()));
      append(result, "Eras", Arrays.toString(dfs.getEras()));
      append(result, "Months", Arrays.toString(dfs.getMonths()));
      append(result, "Short Months", Arrays.toString(dfs.getShortMonths()));
      append(result, "Weekdays", Arrays.toString(dfs.getWeekdays()));
      append(result, "Short Weekdays", Arrays.toString(dfs.getShortWeekdays()));
    }

    result.append("<p><b>Calendar</b><p>");
    Calendar c = Calendar.getInstance(locale);
    int firstDayOfWeek = c.getFirstDayOfWeek();
    String firstDayOfWeekString = new DateFormatSymbols(locale).getWeekdays()[firstDayOfWeek];
    String englishFirstDayOfWeekString =
        new DateFormatSymbols(Locale.US).getWeekdays()[firstDayOfWeek];
    String firstDayOfWeekDetails = firstDayOfWeek + " '" + firstDayOfWeekString + "'";
    if (!englishFirstDayOfWeekString.equals(firstDayOfWeekString)) {
      firstDayOfWeekDetails += " (" + englishFirstDayOfWeekString + ")";
    }
    append(result, "First Day of the Week", firstDayOfWeekDetails);
    append(result, "Minimal Days in First Week", c.getMinimalDaysInFirstWeek());

    // If this locale specifies a country, check out the currency.
    // Languages don't have currencies; countries do.
    if (!locale.getCountry().equals("")) {
      result.append("<p><b>Currency</b><p>");
      try {
        Currency currency = Currency.getInstance(locale);
        append(result, "ISO 4217 Currency Code", currency.getCurrencyCode());
        append(
            result,
            "Currency Symbol",
            unicodeString(currency.getSymbol(locale)) + " (" + currency.getSymbol(Locale.US) + ")");
        append(result, "Default Fraction Digits", currency.getDefaultFractionDigits());
      } catch (IllegalArgumentException ex) {
        result.append(
            "<p>(This version of Android is unable to return a Currency for this Locale.)");
      }
    }

    result.append("<p><b>Data Availability</b><p>");
    appendAvailability(result, locale, "BreakIterator", BreakIterator.class);
    appendAvailability(result, locale, "Calendar", NumberFormat.class);
    appendAvailability(result, locale, "Collator", Collator.class);
    appendAvailability(result, locale, "DateFormat", DateFormat.class);
    appendAvailability(result, locale, "DateFormatSymbols", DateFormatSymbols.class);
    appendAvailability(result, locale, "DecimalFormatSymbols", DecimalFormatSymbols.class);
    appendAvailability(result, locale, "NumberFormat", NumberFormat.class);

    if (hasLocaleData) {
      result.append("<p><b>libcore.icu.LocaleData</b>");
      try {
        Object enUsData = getLocaleDataInstance(Locale.US);
        Object localeData = getLocaleDataInstance(locale);
        String[] previous;

        result.append("<p>");
        describeStringArray(result, "amPm", enUsData, localeData, null);
        describeStringArray(result, "eras", enUsData, localeData, null);

        result.append("<p>");
        previous = describeStringArray(result, "longMonthNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortMonthNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyMonthNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneMonthNames", enUsData, localeData, previous);

        result.append("<p>");
        previous = describeStringArray(result, "longWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneWeekdayNames", enUsData, localeData, previous);

        result.append("<p>");
        describeString(result, "yesterday", enUsData, localeData);
        describeString(result, "today", enUsData, localeData);
        describeString(result, "tomorrow", enUsData, localeData);

        result.append("<p>");
        describeString(result, "timeFormat12", enUsData, localeData);
        describeString(result, "timeFormat24", enUsData, localeData);

        result.append("<p>");
        describeChar(result, "zeroDigit", enUsData, localeData);
        describeChar(result, "decimalSeparator", enUsData, localeData);
        describeChar(result, "groupingSeparator", enUsData, localeData);
        describeChar(result, "patternSeparator", enUsData, localeData);
        describeChar(result, "percent", enUsData, localeData);
        describeChar(result, "perMill", enUsData, localeData);
        describeChar(result, "monetarySeparator", enUsData, localeData);
        describeChar(result, "minusSign", enUsData, localeData);
        describeString(result, "exponentSeparator", enUsData, localeData);
        describeString(result, "infinity", enUsData, localeData);
        describeString(result, "NaN", enUsData, localeData);

      } catch (Exception ex) {
        result.append("(" + ex.getClass().getSimpleName() + " thrown: " + ex.getMessage() + ")");
        System.err.println(ex);
      }
    }

    return result.toString();
  }