Example #1
0
 @SuppressWarnings("deprecation")
 private void fill0(DateTimeOption option, boolean doRecover) throws CsvFormatException {
   if (lineBuffer.hasRemaining()) {
     long value = dateTimeFormat.parse(lineBuffer);
     if (value < 0) {
       if (doRecover && trimWhitespaces()) {
         fill0(option, false);
         return;
       }
       throw new CsvFormatException(
           createStatusInLine(Reason.INVALID_CELL_FORMAT, dateTimeFormat.getPattern()), null);
     }
     option.modify(value);
   } else {
     option.setNull();
   }
 }
Example #2
0
  public static void main(String[] args) {
    ZonedDateTime apollo11launch =
        ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));

    String formatted = DateTimeFormatter.ISO_DATE_TIME.format(apollo11launch);
    // 1969-07-16T09:32:00-05:00[America/New_York]
    System.out.println(formatted);

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
    formatted = formatter.format(apollo11launch);
    // July 16, 1969 9:32:00 AM EDT
    System.out.println(formatted);
    formatted = formatter.withLocale(Locale.FRENCH).format(apollo11launch);
    // 16 juillet 1969 09:32:00 EDT
    System.out.println(formatted);

    formatter = DateTimeFormatter.ofPattern("E yyyy-MM-dd HH:mm");
    formatted = formatter.format(apollo11launch);
    System.out.println(formatted);

    LocalDate churchsBirthday = LocalDate.parse("1903-06-14");
    System.out.println("churchsBirthday: " + churchsBirthday);
    apollo11launch =
        ZonedDateTime.parse(
            "1969-07-16 03:32:00-0400", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssxx"));
    System.out.println("apollo11launch: " + apollo11launch);
  }
 /**
  * Constructor.
  *
  * @param locale the locale of the culture, not null
  * @param zeroChar the character to use for the digit of zero
  * @param positiveSignChar the character to use for the positive sign
  * @param negativeSignChar the character to use for the negative sign
  * @param decimalPointChar the character to use for the decimal point
  * @param firstDayOfWeek the first day of the week
  * @param minDaysInFirstWeek the minimum number of days in the first week, 1 to 7
  */
 public DateTimeFormatSymbols(
     Locale locale,
     char zeroChar,
     char positiveSignChar,
     char negativeSignChar,
     char decimalPointChar,
     DayOfWeek firstDayOfWeek,
     int minDaysInFirstWeek) {
   DateTimeFormatter.checkNotNull(locale, "Locale must not be null");
   DateTimeFormatter.checkNotNull(firstDayOfWeek, "DayOfWeek must not be null");
   this.locale = locale;
   this.zeroDigit = zeroChar;
   this.positiveSign = positiveSignChar;
   this.negativeSign = negativeSignChar;
   this.decimalSeparator = decimalPointChar;
   this.firstDayOfWeek = firstDayOfWeek;
   this.minDaysInFirstWeek = minDaysInFirstWeek;
 }
 /**
  * Obtains an info for the specified locale.
  *
  * <p>This method provides access to locale sensitive information.
  *
  * @param locale the locale, not null
  * @return the info, not null
  */
 public static DateTimeFormatSymbols of(Locale locale) {
   DateTimeFormatter.checkNotNull(locale, "Locale must not be null");
   DateTimeFormatSymbols info = CACHE.get(locale);
   if (info == null) {
     info = createInfo(locale);
     CACHE.putIfAbsent(locale, info);
     info = CACHE.get(locale);
   }
   return info;
 }
Example #5
0
  /**
   * Creates a new instance.
   *
   * @param stream the source stream
   * @param path the source path
   * @param config current configuration
   * @throws IllegalArgumentException if some parameters were {@code null}
   */
  public CsvParser(InputStream stream, String path, CsvConfiguration config) {
    if (stream == null) {
      throw new IllegalArgumentException("stream must not be null"); // $NON-NLS-1$
    }
    if (config == null) {
      throw new IllegalArgumentException("config must not be null"); // $NON-NLS-1$
    }
    this.reader = new InputStreamReader(stream, config.getCharset());
    this.path = path;
    this.separator = config.getSeparatorChar();
    this.trueFormat = config.getTrueFormat();
    this.dateFormat = DateFormatter.newInstance(config.getDateFormat());
    this.dateTimeFormat = DateTimeFormatter.newInstance(config.getDateTimeFormat());
    this.headerCellsFormat = config.getHeaderCells();
    this.forceConsumeHeader = config.isForceConsumeHeader();
    this.allowLineBreakInValue = config.isLineBreakInValue();

    readerBuffer.clear();
    readerBuffer.flip();
  }
  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);
  }