org.threeten.bp.LocalDate Java Examples

The following examples show how to use org.threeten.bp.LocalDate. 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: FakeApiTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 
 *
 * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void testEndpointParametersTest() throws ApiException {
    BigDecimal number = null;
    Double _double = null;
    String patternWithoutDelimiter = null;
    byte[] _byte = null;
    Integer integer = null;
    Integer int32 = null;
    Long int64 = null;
    Float _float = null;
    String string = null;
    File binary = null;
    LocalDate date = null;
    OffsetDateTime dateTime = null;
    String password = null;
    String paramCallback = null;
    api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);

    // TODO: test validations
}
 
Example #2
Source File: ApiClient.java    From swaggy-jenkins with MIT License 6 votes vote down vote up
/**
 * Format the given parameter object into string.
 *
 * @param param Parameter
 * @return String representation of the parameter
 */
public String parameterToString(Object param) {
    if (param == null) {
        return "";
    } else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
        //Serialize to json string and remove the " enclosing characters
        String jsonStr = json.serialize(param);
        return jsonStr.substring(1, jsonStr.length() - 1);
    } else if (param instanceof Collection) {
        StringBuilder b = new StringBuilder();
        for (Object o : (Collection)param) {
            if (b.length() > 0) {
                b.append(",");
            }
            b.append(String.valueOf(o));
        }
        return b.toString();
    } else {
        return String.valueOf(param);
    }
}
 
Example #3
Source File: TestThaiBuddhistChronology.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@DataProvider(name="samples")
Object[][] data_samples() {
    return new Object[][] {
        {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)},
        {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 2), LocalDate.of(1, 1, 2)},
        {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 3), LocalDate.of(1, 1, 3)},

        {ThaiBuddhistChronology.INSTANCE.date(2 + YDIFF, 1, 1), LocalDate.of(2, 1, 1)},
        {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 1, 1), LocalDate.of(3, 1, 1)},
        {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 12, 6), LocalDate.of(3, 12, 6)},
        {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 1, 1), LocalDate.of(4, 1, 1)},
        {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 3), LocalDate.of(4, 7, 3)},
        {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 4), LocalDate.of(4, 7, 4)},
        {ThaiBuddhistChronology.INSTANCE.date(5 + YDIFF, 1, 1), LocalDate.of(5, 1, 1)},
        {ThaiBuddhistChronology.INSTANCE.date(1662 + YDIFF, 3, 3), LocalDate.of(1662, 3, 3)},
        {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 28), LocalDate.of(1728, 10, 28)},
        {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 29), LocalDate.of(1728, 10, 29)},
        {ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), LocalDate.of(2012, 8, 29)},
    };
}
 
Example #4
Source File: JapaneseDate.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar
 * system from the era, year-of-era and day-of-year fields.
 * <p>
 * This returns a {@code JapaneseDate} with the specified fields.
 * The day must be valid for the year, otherwise an exception will be thrown.
 * The Japanese day-of-year is reset when the era changes.
 *
 * @param era  the Japanese era, not null
 * @param yearOfEra  the Japanese year-of-era
 * @param dayOfYear  the Japanese day-of-year, from 1 to 31
 * @return the date in Japanese calendar system, not null
 * @throws DateTimeException if the value of any field is out of range,
 *  or if the day-of-year is invalid for the year
 */
static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) {
    Jdk8Methods.requireNonNull(era, "era");
    if (yearOfEra < 1) {
        throw new DateTimeException("Invalid YearOfEra: " + yearOfEra);
    }
    LocalDate eraStartDate = era.startDate();
    LocalDate eraEndDate = era.endDate();
    if (yearOfEra == 1) {
        dayOfYear += eraStartDate.getDayOfYear() - 1;
        if (dayOfYear > eraStartDate.lengthOfYear()) {
            throw new DateTimeException("DayOfYear exceeds maximum allowed in the first year of era " + era);
        }
    }
    int yearOffset = eraStartDate.getYear() - 1;
    LocalDate isoDate = LocalDate.ofYearDay(yearOfEra + yearOffset, dayOfYear);
    if (isoDate.isBefore(eraStartDate) || isoDate.isAfter(eraEndDate)) {
        throw new DateTimeException("Requested date is outside bounds of era " + era);
    }
    return new JapaneseDate(era, yearOfEra, isoDate);
}
 
Example #5
Source File: IsoFields.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example #6
Source File: FakeApiTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 
 *
 * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 
 */
@Test
public void testEndpointParametersTest() {
    BigDecimal number = null;
    Double _double = null;
    String patternWithoutDelimiter = null;
    byte[] _byte = null;
    Integer integer = null;
    Integer int32 = null;
    Long int64 = null;
    Float _float = null;
    String string = null;
    File binary = null;
    LocalDate date = null;
    OffsetDateTime dateTime = null;
    String password = null;
    String paramCallback = null;
    // api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);

    // TODO: test validations
}
 
Example #7
Source File: Quote.java    From Xero-Java with MIT License 5 votes vote down vote up
public void setDate(LocalDate date) {
  //CONVERT LocalDate args into MS DateFromat String
  Instant instant =  date.atStartOfDay(ZoneId.of("UTC").normalized()).toInstant();  
  long timeInMillis = instant.toEpochMilli();

  this.date = "/Date(" + Long.toString(timeInMillis) + "+0000)/";
}
 
Example #8
Source File: Organisation.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getEndOfYearLockDateAsDate() {
  if (this.endOfYearLockDate != null) {
    try {
      return util.convertStringToDate(this.endOfYearLockDate);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #9
Source File: PayRun.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getPayRunPeriodEndDateAsDate() {
  if (this.payRunPeriodEndDate != null) {
    try {
      return util.convertStringToDate(this.payRunPeriodEndDate);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #10
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public JSON() {
    gson = createGson()
        .registerTypeAdapter(Date.class, dateTypeAdapter)
        .registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
        .registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
        .registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
        .registerTypeAdapter(byte[].class, byteArrayAdapter)
        .create();
}
 
Example #11
Source File: LeavePeriod.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getPayPeriodEndDateAsDate() {
  if (this.payPeriodEndDate != null) {
    try {
      return util.convertStringToDate(this.payPeriodEndDate);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #12
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfMonth_nonLeap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #13
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfNextYear_nonLeap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), JANUARY);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #14
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, LocalDate date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        out.value(formatter.format(date));
    }
}
 
Example #15
Source File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public LocalDate read(JsonReader in) throws IOException {
    switch (in.peek()) {
        case NULL:
            in.nextNull();
            return null;
        default:
            String date = in.nextString();
            return LocalDate.parse(date, formatter);
    }
}
 
Example #16
Source File: BatchPayment.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getDateAsDate() {
  if (this.date != null) {
    try {
      return util.convertStringToDate(this.date);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #17
Source File: TestDateTimeFormatter.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_toFormat_format() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example #18
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_previousOrSame() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff <= 0 && dayDiff > -7);
                    assertEquals(date.equals(test), date.getDayOfWeek() == dow);
                } else {
                    assertFalse(date.getDayOfWeek() == dow);
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 7);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 25);
                }
            }
        }
    }
}
 
Example #19
Source File: MonthView.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override protected void buildDayViews(
    final Collection<DayView> dayViews,
    final LocalDate calendar) {
  LocalDate temp = calendar;
  for (int r = 0; r < DEFAULT_MAX_WEEKS; r++) {
    for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
      addDayView(dayViews, temp);
      temp = temp.plusDays(1);
    }
  }
}
 
Example #20
Source File: TestChronoUnit.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider = "monthsBetween")
public void test_monthsBetween_ZonedDateLaterOffset(LocalDate start, LocalDate end, long expected) {
    // +01:00 is later than +02:00
    if (end.isAfter(start)) {
        assertEquals(MONTHS.between(start.atStartOfDay(ZoneOffset.ofHours(2)), end.atStartOfDay(ZoneOffset.ofHours(1))), expected);
    } else {
        assertEquals(MONTHS.between(start.atStartOfDay(ZoneOffset.ofHours(1)), end.atStartOfDay(ZoneOffset.ofHours(2))), expected);
    }
}
 
Example #21
Source File: CreditNote.java    From Xero-Java with MIT License 5 votes vote down vote up
public void setFullyPaidOnDate(LocalDate fullyPaidOnDate) {
  //CONVERT LocalDate args into MS DateFromat String
  Instant instant =  fullyPaidOnDate.atStartOfDay(ZoneId.of("UTC").normalized()).toInstant();  
  long timeInMillis = instant.toEpochMilli();

  this.fullyPaidOnDate = "/Date(" + Long.toString(timeInMillis) + "+0000)/";
}
 
Example #22
Source File: PayRun.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getPayRunPeriodStartDateAsDate() {
  if (this.payRunPeriodStartDate != null) {
    try {
      return util.convertStringToDate(this.payRunPeriodStartDate);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #23
Source File: Employee.java    From Xero-Java with MIT License 5 votes vote down vote up
public LocalDate getTerminationDateAsDate() {
  if (this.terminationDate != null) {
    try {
      return util.convertStringToDate(this.terminationDate);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
  return null;        
}
 
Example #24
Source File: LocalDateConverterTest.java    From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
    LocalDate localDate = LocalDate.parse("2010-08-20");

    String json = gson.toJson(localDate);

    assertEquals(json, "\"2010-08-20\"");
}
 
Example #25
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, LocalDate date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        out.value(formatter.format(date));
    }
}
 
Example #26
Source File: Schedule.java    From Xero-Java with MIT License 5 votes vote down vote up
public void setNextScheduledDate(LocalDate nextScheduledDate) {
  //CONVERT LocalDate args into MS DateFromat String
  Instant instant =  nextScheduledDate.atStartOfDay(ZoneId.of("UTC").normalized()).toInstant();  
  long timeInMillis = instant.toEpochMilli();

  this.nextScheduledDate = "/Date(" + Long.toString(timeInMillis) + "+0000)/";
}
 
Example #27
Source File: IsoFields.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long getFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(this) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: WeekOfWeekBasedYear");
    }
    return getWeek(LocalDate.from(temporal));
}
 
Example #28
Source File: DateTimeBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void mergeDate(ResolverStyle resolverStyle) {
    if (chrono instanceof IsoChronology) {
        checkDate(IsoChronology.INSTANCE.resolveDate(fieldValues, resolverStyle));
    } else {
        if (fieldValues.containsKey(EPOCH_DAY)) {
            checkDate(LocalDate.ofEpochDay(fieldValues.remove(EPOCH_DAY)));
            return;
        }
    }
}
 
Example #29
Source File: ChronoDateImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
    ChronoLocalDate end = getChronology().date(endExclusive);
    if (unit instanceof ChronoUnit) {
        return LocalDate.from(this).until(end, unit);  // TODO: this is wrong
    }
    return unit.between(this, end);
}
 
Example #30
Source File: FormatTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Get date
 * @return date
**/
@ApiModelProperty(required = true, value = "")
@JsonProperty(JSON_PROPERTY_DATE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

public LocalDate getDate() {
  return date;
}