org.threeten.bp.format.DateTimeFormatter Java Examples

The following examples show how to use org.threeten.bp.format.DateTimeFormatter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
protected CustomInstantDeserializer(Class<T> supportedType,
                  DateTimeFormatter parser,
                  Function<TemporalAccessor, T> parsedToValue,
                  Function<FromIntegerArguments, T> fromMilliseconds,
                  Function<FromDecimalArguments, T> fromNanoseconds,
                  BiFunction<T, ZoneId, T> adjust) {
  super(supportedType, parser);
  this.parsedToValue = parsedToValue;
  this.fromMilliseconds = fromMilliseconds;
  this.fromNanoseconds = fromNanoseconds;
  this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
    @Override
    public T apply(T t, ZoneId zoneId) {
      return t;
    }
  } : adjust;
}
 
Example #2
Source File: AppDumperPlugin.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void displayAlarms(PrintStream writer) {
    sessionsDao.getSessions()
            .flatMap(Observable::from)
            .map(session -> {
                Intent intent = new ReminderReceiverIntentBuilder(session).build(context);
                PendingIntent broadcast = PendingIntent.getBroadcast(context, session.getId(), intent, PendingIntent.FLAG_NO_CREATE);
                if (broadcast != null) {
                    return String.format(Locale.US, "%s - Session(id=%d, title=%s)", session.getFromTime().format(DateTimeFormatter.ISO_DATE_TIME), session.getId(), session.getTitle());
                }
                return null;
            })
            .filter(id -> id != null)
            .toList()
            .subscribe(activeAlarms -> {
                writer.println(Integer.toString(activeAlarms.size()) + " active alarm(s)");
                for (String activeAlarm : activeAlarms) {
                    writer.println(activeAlarm);
                }
            });
}
 
Example #3
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
  if (dtf == _formatter) {
    return this;
  }
  return new CustomInstantDeserializer<T>(this, dtf);
}
 
Example #4
Source File: SearchBar.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
public DateTimeFormatter getSearchBarClockFormat(Integer id) {
    if (_clockFormatterIndex != id && id > 0) {
        if (_clockModes.containsKey(id)) {
            return _clockModes.get(id);
        }
    }

    return Setup.appSettings().getUserDateFormat();
}
 
Example #5
Source File: SessionDetailsActivity.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
private void bindTalkInfo(Session session) {
    DateTimeFormatter timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
    String day = session.getFromTime().format(DateTimeFormatter.ofPattern(getString(R.string.session_details_talk_info_date_pattern)));
    String fromTime = session.getFromTime().format(timeFormatter);
    String toTime = session.getToTime().format(timeFormatter);
    String room = session.getRoom();
    talkInfo.setText(Strings.capitalizeFirstLetter(getString(R.string.session_details_talk_info, day, fromTime, toTime, room)));
}
 
Example #6
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
  super((Class<T>) base.handledType(), f);
  parsedToValue = base.parsedToValue;
  fromMilliseconds = base.fromMilliseconds;
  fromNanoseconds = base.fromNanoseconds;
  adjust = base.adjust;
}
 
Example #7
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
  if (dtf == _formatter) {
    return this;
  }
  return new CustomInstantDeserializer<T>(this, dtf);
}
 
Example #8
Source File: Performance.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void formatListTime(List<LocalTime> list) {
    StringBuilder buf = new StringBuilder();
    DateTimeFormatter format = DateTimeFormatter.ISO_TIME.withLocale(Locale.ENGLISH);
    long start = System.nanoTime();
    for (LocalTime dt : list) {
        buf.setLength(0);
        buf.append(format.format(dt));
    }
    long end = System.nanoTime();
    System.out.println("LocalT:    Format: " + NF.format(end - start) + " ns" + " " + buf);
    result("LocalT-P", end - start);
}
 
Example #9
Source File: UsabilityBasic.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void print2() {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendText(ChronoField.MONTH_OF_YEAR)
            .appendLiteral(' ').appendValue(ChronoField.YEAR).toFormatter();
    System.out.println(f.format(LocalDate.now()));
    System.out.println(f.format(YearMonth.now()));
    System.out.println(f.format(ZonedDateTime.now()));
}
 
Example #10
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
  super((Class<T>) base.handledType(), f);
  parsedToValue = base.parsedToValue;
  fromMilliseconds = base.fromMilliseconds;
  fromNanoseconds = base.fromNanoseconds;
  adjust = base.adjust;
}
 
Example #11
Source File: Performance.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void formatListZonedDateTime(List<ZonedDateTime> list) {
    StringBuilder buf = new StringBuilder();
    DateTimeFormatter format = DateTimeFormatter.ISO_DATE.withLocale(Locale.ENGLISH);
    long start = System.nanoTime();
    for (ZonedDateTime dt : list) {
        buf.setLength(0);
        buf.append(format.format(dt));
    }
    long end = System.nanoTime();
    System.out.println("ZonedDT:   Format: " + NF.format(end - start) + " ns" + " " + buf);
    result("ZonedDT-P", end - start);
}
 
Example #12
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
  super((Class<T>) base.handledType(), f);
  parsedToValue = base.parsedToValue;
  fromMilliseconds = base.fromMilliseconds;
  fromNanoseconds = base.fromNanoseconds;
  adjust = base.adjust;
}
 
Example #13
Source File: DataHelper.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper function to insert user data. For example, the data entered for
 * numeric format, or date for date format The timestamp is updated within
 * this function as well
 * v1.6 - Amended to consider both trait and user data
 */
public long insertUserTraits(String rid, String parent, String trait, String userValue, String person, String location, String notes, String exp_id, String observationDbId, OffsetDateTime lastSyncedTime) {

    Cursor cursor = db.rawQuery("SELECT * from user_traits WHERE user_traits.rid = ? and user_traits.parent = ?", new String[]{rid, parent});
    int rep = cursor.getCount() + 1;

    try {
        this.insertUserTraits.bindString(1, rid);
        this.insertUserTraits.bindString(2, parent);
        this.insertUserTraits.bindString(3, trait);
        this.insertUserTraits.bindString(4, userValue);
        this.insertUserTraits.bindString(5, timeStamp.format(Calendar.getInstance().getTime()));
        this.insertUserTraits.bindString(6, person);
        this.insertUserTraits.bindString(7, location);
        this.insertUserTraits.bindString(8, Integer.toString(rep));
        this.insertUserTraits.bindString(9, notes);
        this.insertUserTraits.bindString(10, exp_id);
        if (observationDbId != null) {
            this.insertUserTraits.bindString(11, observationDbId);
        } else {
            this.insertUserTraits.bindNull(11);
        }
        if (lastSyncedTime != null) {
            this.insertUserTraits.bindString(12, lastSyncedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.getDefault())));
        } else {
            this.insertUserTraits.bindNull(12);
        }

        return this.insertUserTraits.executeInsert();
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example #14
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
  if (dtf == _formatter) {
    return this;
  }
  return new CustomInstantDeserializer<T>(this, dtf);
}
 
Example #15
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
  if (dtf == _formatter) {
    return this;
  }
  return new CustomInstantDeserializer<T>(this, dtf);
}
 
Example #16
Source File: CloudSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
/** Example of running a query with timestamp query parameters. */
public void runQueryWithTimestampParameters() throws InterruptedException {
  // [START bigquery_query_params_timestamps]
  // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
  ZonedDateTime timestamp = LocalDateTime.of(2016, 12, 7, 8, 0, 0).atZone(ZoneOffset.UTC);
  String query = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);";
  // Note: Standard SQL is required to use query parameters.
  QueryJobConfiguration queryConfig =
      QueryJobConfiguration.newBuilder(query)
          .addNamedParameter(
              "ts_value",
              QueryParameterValue.timestamp(
                  // Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
                  timestamp.toInstant().toEpochMilli() * 1000))
          .build();

  // Print the results.
  DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT.withZone(ZoneOffset.UTC);
  for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
    System.out.printf(
        "%s\n",
        formatter.format(
            Instant.ofEpochMilli(
                    // Timestamp values are returned in microseconds since 1970-01-01T00:00:00
                    // UTC,
                    // but org.joda.time.DateTime constructor accepts times in milliseconds.
                    row.get(0).getTimestampValue() / 1000)
                .atOffset(ZoneOffset.UTC)));
    System.out.printf("\n");
  }
  // [END bigquery_query_params_timestamps]
}
 
Example #17
Source File: TestOffsetDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M d H m s");
    OffsetDateTime.parse((String) null, f);
}
 
Example #18
Source File: JSON.java    From oxd with Apache License 2.0 4 votes vote down vote up
public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
    offsetDateTimeTypeAdapter.setFormat(dateFormat);
    return this;
}
 
Example #19
Source File: TestOffsetTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX");
    OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
    assertEquals(test, OffsetTime.of(LocalTime.of(11, 30), ZoneOffset.ofHours(1)));
}
 
Example #20
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) {
    this.json.setLocalDateFormat(dateFormat);
    return this;
}
 
Example #21
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
    this.json.setOffsetDateTimeFormat(dateFormat);
    return this;
}
 
Example #22
Source File: JSON.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public JSON setLocalDateFormat(DateTimeFormatter dateFormat) {
    localDateTypeAdapter.setFormat(dateFormat);
    return this;
}
 
Example #23
Source File: JSON.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
public OffsetDateTimeTypeAdapter() {
    this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
 
Example #24
Source File: TestZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("u M d H m s VV");
    ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
    assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
}
 
Example #25
Source File: JSON.java    From swaggy-jenkins with MIT License 4 votes vote down vote up
public LocalDateTypeAdapter(DateTimeFormatter formatter) {
    this.formatter = formatter;
}
 
Example #26
Source File: JSON.java    From oxd with Apache License 2.0 4 votes vote down vote up
public JSON setLocalDateFormat(DateTimeFormatter dateFormat) {
    localDateTypeAdapter.setFormat(dateFormat);
    return this;
}
 
Example #27
Source File: DateFormatDayFormatter.java    From material-calendarview with MIT License 4 votes vote down vote up
/**
 * Format using a default format
 */
public DateFormatDayFormatter() {
  this(DateTimeFormatter.ofPattern(DEFAULT_FORMAT, Locale.getDefault()));
}
 
Example #28
Source File: JSON.java    From swaggy-jenkins with MIT License 4 votes vote down vote up
public void setFormat(DateTimeFormatter dateFormat) {
    this.formatter = dateFormat;
}
 
Example #29
Source File: AppSettings.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
public DateTimeFormatter getUserDateFormat() {
    String line1 = getString(R.string.pref_key__date_bar_date_format_custom_1, rstr(R.string.pref_default__date_bar_date_format_custom_1));
    String line2 = getString(R.string.pref_key__date_bar_date_format_custom_2, rstr(R.string.pref_default__date_bar_date_format_custom_2));

    return DateTimeFormatter.ofPattern(line1 +  "'\n'" + line2);
}
 
Example #30
Source File: JSON.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
    offsetDateTimeTypeAdapter.setFormat(dateFormat);
    return this;
}