java.time.Month Java Examples

The following examples show how to use java.time.Month. 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: TCKZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void test_London_getTransitionRules() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    assertEquals(rules.size(), 2);

    ZoneOffsetTransitionRule in = rules.get(0);
    assertEquals(in.getMonth(), Month.MARCH);
    assertEquals(in.getDayOfMonthIndicator(), 25);  // optimized from -1
    assertEquals(in.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(in.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(in.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(in.getStandardOffset(), OFFSET_ZERO);
    assertEquals(in.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(in.getOffsetAfter(), OFFSET_PONE);

    ZoneOffsetTransitionRule out = rules.get(1);
    assertEquals(out.getMonth(), Month.OCTOBER);
    assertEquals(out.getDayOfMonthIndicator(), 25);  // optimized from -1
    assertEquals(out.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(out.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(out.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(out.getStandardOffset(), OFFSET_ZERO);
    assertEquals(out.getOffsetBefore(), OFFSET_PONE);
    assertEquals(out.getOffsetAfter(), OFFSET_ZERO);
}
 
Example #2
Source File: IsoChronology.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override  // override for performance
LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
    }
    int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
    int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH));
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
            dom = Math.min(dom, 30);
        } else if (moy == 2) {
            dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y)));

        }
    }
    return LocalDate.of(y, moy, dom);
}
 
Example #3
Source File: TCKOffsetDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example #4
Source File: Formats.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
/**
 * Registers the default parsers for these formats
 * NOTE THAT THE ORDER IN WHICH THESE ARE REGISTERED MATTERS SOMEWHAT (MORE SPECIFIC TO LESS SPECIFIC)
 */
private void registerParsers() {
    this.setParser(boolean.class, Parser.ofBoolean().withNullChecker(nullCheck));
    this.setParser(Boolean.class, Parser.ofBoolean().withNullChecker(nullCheck));
    this.setParser(int.class, Parser.ofInteger().withNullChecker(nullCheck));
    this.setParser(Integer.class, Parser.ofInteger().withNullChecker(nullCheck));
    this.setParser(long.class, Parser.ofLong().withNullChecker(nullCheck));
    this.setParser(Long.class, Parser.ofLong().withNullChecker(nullCheck));
    this.setParser(double.class, Parser.ofDouble("0.0000####;-0.0000####", 1).withNullChecker(nullCheck));
    this.setParser(Double.class, Parser.ofDouble("0.0000####;-0.0000####", 1).withNullChecker(nullCheck));
    this.setParser(BigDecimal.class, Parser.ofBigDecimal().withNullChecker(nullCheck));
    this.setParser(LocalDate.class, Parser.ofLocalDate(DateTimeFormatter.ISO_LOCAL_DATE).withNullChecker(nullCheck));
    this.setParser(LocalTime.class, Parser.ofLocalTime(DateTimeFormatter.ISO_LOCAL_TIME).withNullChecker(nullCheck));
    this.setParser(LocalDateTime.class, Parser.ofLocalDateTime(DateTimeFormatter.ISO_LOCAL_DATE_TIME).withNullChecker(nullCheck));
    this.setParser(ZonedDateTime.class, Parser.ofZonedDateTime(DateTimeFormatter.ISO_ZONED_DATE_TIME).withNullChecker(nullCheck));
    this.setParser(Period.class, Parser.ofPeriod().withNullChecker(nullCheck));
    this.setParser(ZoneId.class, Parser.ofZoneId().withNullChecker(nullCheck));
    this.setParser(Month.class, Parser.ofEnum(Month.class).withNullChecker(nullCheck));
    this.setParser(TimeZone.class, Parser.ofTimeZone().withNullChecker(nullCheck));
    this.setParser(java.util.Date.class, Parser.ofDate().withNullChecker(nullCheck));
    this.setParser(String.class, Parser.ofString().withNullChecker(nullCheck));
    this.setParser(Object.class, Parser.ofObject().withNullChecker(nullCheck));
}
 
Example #5
Source File: TimeSeriesLoaderTest.java    From java-trader with Apache License 2.0 6 votes vote down vote up
@Test
public void testBarIndex_au1906() {
    Exchangeable au1906 = Exchangeable.fromString("au1906");
    LocalDateTime time = LocalDateTime.of(2018, Month.DECEMBER, 13, 02, 29);
    ExchangeableTradingTimes tradingTimes = au1906.exchange().detectTradingTimes(au1906, time);

    LocalDateTime time2 = LocalDateTime.of(2018, Month.DECEMBER, 13, 02, 30);
    int barIndex2 = BarSeriesLoader.getBarIndex(tradingTimes, PriceLevel.MIN1, time2);
    int barIndex = BarSeriesLoader.getBarIndex(tradingTimes, PriceLevel.MIN1, time);

    LocalDateTime time3 = LocalDateTime.of(2018, Month.DECEMBER, 13, 02, 30, 00).withNano(500*1000000);
    int barIndex3 = BarSeriesLoader.getBarIndex(tradingTimes, PriceLevel.MIN1, time3);
    assertTrue(barIndex==barIndex3);

    assertTrue(barIndex==barIndex2);
}
 
Example #6
Source File: LIBORMarketModelCalibrationAADTest.java    From finmath-lib with Apache License 2.0 6 votes vote down vote up
public static AnalyticModel getCalibratedCurve() throws SolverException {
	final String[] maturity					= { "6M", "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "35Y", "40Y", "45Y", "50Y" };
	final String[] frequency				= { "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual", "annual" };
	final String[] frequencyFloat			= { "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual", "semiannual" };
	final String[] daycountConventions		= { "ACT/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360", "E30/360" };
	final String[] daycountConventionsFloat	= { "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360", "ACT/360" };
	final double[] rates					= { -0.00216 ,-0.00208 ,-0.00222 ,-0.00216 ,-0.0019 ,-0.0014 ,-0.00072 ,0.00011 ,0.00103 ,0.00196 ,0.00285 ,0.00367 ,0.0044 ,0.00604 ,0.00733 ,0.00767 ,0.00773 ,0.00765 ,0.00752 ,0.007138 ,0.007 };

	final HashMap<String, Object> parameters = new HashMap<>();

	parameters.put("referenceDate", LocalDate.of(2016, Month.SEPTEMBER, 30));
	parameters.put("currency", "EUR");
	parameters.put("forwardCurveTenor", "6M");
	parameters.put("maturities", maturity);
	parameters.put("fixLegFrequencies", frequency);
	parameters.put("floatLegFrequencies", frequencyFloat);
	parameters.put("fixLegDaycountConventions", daycountConventions);
	parameters.put("floatLegDaycountConventions", daycountConventionsFloat);
	parameters.put("rates", rates);

	return getCalibratedCurve(null, parameters);
}
 
Example #7
Source File: IsoChronology.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override  // override for performance
LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
    }
    int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
    int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH));
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
            dom = Math.min(dom, 30);
        } else if (moy == 2) {
            dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y)));

        }
    }
    return LocalDate.of(y, moy, dom);
}
 
Example #8
Source File: ZoneOffsetTransitionRule.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance defining the yearly rule to create transitions between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param month  the month of the month-day of the first day of the cutover week, not null
 * @param dayOfMonthIndicator  the day of the month-day of the cutover week, positive if the week is that
 *  day or later, negative if the week is that day or earlier, counting from the last day of the month,
 *  from -28 to 31 excluding 0
 * @param dayOfWeek  the required day-of-week, null if the month-day should not be changed
 * @param time  the cutover time in the 'before' offset, not null
 * @param timeEndOfDay  whether the time is midnight at the end of day
 * @param timeDefnition  how to interpret the cutover
 * @param standardOffset  the standard offset in force at the cutover, not null
 * @param offsetBefore  the offset before the cutover, not null
 * @param offsetAfter  the offset after the cutover, not null
 * @return the rule, not null
 * @throws IllegalArgumentException if the day of month indicator is invalid
 * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
 */
public static ZoneOffsetTransitionRule of(
        Month month,
        int dayOfMonthIndicator,
        DayOfWeek dayOfWeek,
        LocalTime time,
        boolean timeEndOfDay,
        TimeDefinition timeDefnition,
        ZoneOffset standardOffset,
        ZoneOffset offsetBefore,
        ZoneOffset offsetAfter) {
    Objects.requireNonNull(month, "month");
    Objects.requireNonNull(time, "time");
    Objects.requireNonNull(timeDefnition, "timeDefnition");
    Objects.requireNonNull(standardOffset, "standardOffset");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
        throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
    }
    if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
        throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
    }
    return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter);
}
 
Example #9
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleDates")
public void test_get(int y, int m) {
    YearMonth a = YearMonth.of(y, m);
    assertEquals(a.getYear(), y);
    assertEquals(a.getMonth(), Month.of(m));
    assertEquals(a.getMonthValue(), m);
}
 
Example #10
Source File: StreamFindAndMatch.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void stream_findAny() {

	Predicate<HiddenObjectGame> releaseDateInApril = p -> Month.APRIL == p
			.getReleaseDate().getMonth();

	Optional<HiddenObjectGame> hiddenGameReleaseInApril = games.stream()
			.filter(releaseDateInApril).findAny();
	
	assertFalse(hiddenGameReleaseInApril.isPresent());
}
 
Example #11
Source File: TCKTemporalAdjusters.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_previousOrCurrent() {
    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 #12
Source File: DateWrapper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public DateWrapper(final int year, final Month month, final int dayOfMonth, final int hour, final int minute,
		final int second) {
	wrapped = ZonedDateTime
			.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second), ZoneId.systemDefault())
				.toInstant();
	accuracy = ChronoUnit.SECONDS;
}
 
Example #13
Source File: TCKZoneOffsetTransitionRuleSerialization.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_serialization_unusualOffsets() throws Exception {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD,
            ZoneOffset.ofHoursMinutesSeconds(-12, -20, -50),
            ZoneOffset.ofHoursMinutesSeconds(-4, -10, -34),
            ZoneOffset.ofHours(-18));
    assertSerializable(test);
}
 
Example #14
Source File: TCKYearMonth.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    YearMonth test = YearMonth.now(clock);
    assertEquals(test.getYear(), 2010);
    assertEquals(test.getMonth(), Month.DECEMBER);
}
 
Example #15
Source File: TCKLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
    for (int i =-1; i >= -(2 * 24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalDate test = LocalDate.now(clock);
        assertEquals(test.getYear(), 1969);
        assertEquals(test.getMonth(), Month.DECEMBER);
        assertEquals(test.getDayOfMonth(), (i >= -24 * 60 * 60 ? 31 : 30));
    }
}
 
Example #16
Source File: TCKZoneOffsetTransitionRule.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toString_floatingWeek_gap_notEndOfDay() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or after MARCH 20 at 01:00 WALL, standard offset +02:00]");
}
 
Example #17
Source File: TCKMonth.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_isSupported_TemporalField() {
    assertEquals(Month.AUGUST.isSupported((TemporalField) null), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_SECOND), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_SECOND), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_SECOND), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_MINUTE), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_HOUR), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_AMPM), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.AMPM_OF_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_WEEK), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_MONTH), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_YEAR), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.EPOCH_DAY), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.MONTH_OF_YEAR), true);
    assertEquals(Month.AUGUST.isSupported(ChronoField.PROLEPTIC_MONTH), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR_OF_ERA), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.ERA), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.INSTANT_SECONDS), false);
    assertEquals(Month.AUGUST.isSupported(ChronoField.OFFSET_SECONDS), false);
}
 
Example #18
Source File: LocalDateSerTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationAsString02() throws Exception
{
    LocalDate date = LocalDate.of(2013, Month.AUGUST, 21);
    String value = MAPPER.writer()
    		.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
    		.writeValueAsString(date);
    assertNotNull("The value should not be null.", value);
    assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
}
 
Example #19
Source File: TCKZoneOffsetTransitionRule.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equals_null_false() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(a.equals(null), false);
}
 
Example #20
Source File: TCKZoneOffsetTransitionRule.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toString_floatingWeek_overlap_endOfDay() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.OCTOBER, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0300, OFFSET_0200);
    assertEquals(test.toString(), "TransitionRule[Overlap +03:00 to +02:00, SUNDAY on or after OCTOBER 20 at 24:00 WALL, standard offset +02:00]");
}
 
Example #21
Source File: PDTFormatterTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrintDateExplicit ()
{
  final LocalDate aDate = LocalDate.of (2015, Month.FEBRUARY, 1);

  // de-de
  assertEquals ("Sonntag, 1. Februar 2015",
                PDTFormatter.getFormatterDate (FormatStyle.FULL, Locale.GERMANY, EDTFormatterMode.PRINT)
                            .format (aDate));
  assertEquals ("1. Februar 2015",
                PDTFormatter.getFormatterDate (FormatStyle.LONG, Locale.GERMANY, EDTFormatterMode.PRINT)
                            .format (aDate));
  assertEquals ("01.02.2015",
                PDTFormatter.getFormatterDate (FormatStyle.MEDIUM, Locale.GERMANY, EDTFormatterMode.PRINT)
                            .format (aDate));
  assertEquals ("01.02.15",
                PDTFormatter.getFormatterDate (FormatStyle.SHORT, Locale.GERMANY, EDTFormatterMode.PRINT)
                            .format (aDate));

  // en-us
  assertEquals ("Sunday, February 1, 2015",
                PDTFormatter.getFormatterDate (FormatStyle.FULL, Locale.US, EDTFormatterMode.PRINT).format (aDate));
  assertEquals ("February 1, 2015",
                PDTFormatter.getFormatterDate (FormatStyle.LONG, Locale.US, EDTFormatterMode.PRINT).format (aDate));
  assertEquals ("Feb 1, 2015",
                PDTFormatter.getFormatterDate (FormatStyle.MEDIUM, Locale.US, EDTFormatterMode.PRINT).format (aDate));
  assertEquals ("2/1/15",
                PDTFormatter.getFormatterDate (FormatStyle.SHORT, Locale.US, EDTFormatterMode.PRINT).format (aDate));
}
 
Example #22
Source File: FactoryTraffic.java    From Java-9-Cookbook with MIT License 5 votes vote down vote up
public static TrafficUnit getOneUnit(Month month, DayOfWeek dayOfWeek, int hour, String country, String city, String trafficLight){
    double r0 = Math.random(); VehicleType vehicleType = r0<0.4?VehicleType.CAR:(r0>0.6?VehicleType.TRUCK: VehicleType.CAB_CREW);
    double r1 = Math.random();
    double r2 = Math.random();
    double r3 = Math.random();
    return new TrafficModelImpl(vehicleType, gen(4,1), gen(3300,1000), gen(246,100), gen(4000,2000),
            (r1>0.5? RoadCondition.WET: RoadCondition.DRY), (r2>0.5? TireCondition.WORN: TireCondition.NEW),
            r1>0.5?(r3>0.5?63:50):63);
}
 
Example #23
Source File: TCKZoneOffsetTransitionRule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equals_standardOffsetDifferent() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0300, OFFSET_0200, OFFSET_0300);
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);
}
 
Example #24
Source File: JpaPersistenceServiceImplClustersIntegrationTest.java    From genie with Apache License 2.0 5 votes vote down vote up
@Test
@DatabaseSetup("persistence/clusters/init.xml")
void testGetClustersByMinUpdateTime() {
    final ZonedDateTime time = ZonedDateTime.of(2014, Month.JULY.getValue(), 9, 2, 58, 59, 0, ZoneId.of("UTC"));
    final Page<Cluster> clusters = this.service.findClusters(null, null, null, time.toInstant(), null, PAGE);
    Assertions.assertThat(clusters.getNumberOfElements()).isEqualTo(1);
    Assertions.assertThat(clusters.getContent().get(0).getId()).isEqualTo(CLUSTER_2_ID);
}
 
Example #25
Source File: DayCountConventionTest.java    From finmath-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void testDayCountConvention_ACT_360() {
	final DayCountConvention daycountConvention = new DayCountConvention_ACT_360();

	double daycountFraction;

	daycountFraction = daycountConvention.getDaycountFraction(LocalDate.of(2010, Month.MAY, 1), LocalDate.of(2011, Month.AUGUST, 31));
	Assert.assertEquals(487.0/360.0, daycountFraction, 1.0E-4);

	daycountFraction = daycountConvention.getDaycountFraction(LocalDate.of(1999,Month.FEBRUARY,1), LocalDate.of(1999,Month.JULY,1));
	Assert.assertEquals(150.0/360.0, daycountFraction, 1.0E-8);
}
 
Example #26
Source File: TCKZoneOffsetTransitionRule.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equals_offsetAfterDifferent() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0200);
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);
}
 
Example #27
Source File: TCKZoneOffsetTransitionRuleSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_serialization_floatingWeekBackwards() throws Exception {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertSerializable(test);
}
 
Example #28
Source File: TCKMonth.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_maxLength() {
    assertEquals(Month.JANUARY.maxLength(), 31);
    assertEquals(Month.FEBRUARY.maxLength(), 29);
    assertEquals(Month.MARCH.maxLength(), 31);
    assertEquals(Month.APRIL.maxLength(), 30);
    assertEquals(Month.MAY.maxLength(), 31);
    assertEquals(Month.JUNE.maxLength(), 30);
    assertEquals(Month.JULY.maxLength(), 31);
    assertEquals(Month.AUGUST.maxLength(), 31);
    assertEquals(Month.SEPTEMBER.maxLength(), 30);
    assertEquals(Month.OCTOBER.maxLength(), 31);
    assertEquals(Month.NOVEMBER.maxLength(), 30);
    assertEquals(Month.DECEMBER.maxLength(), 31);
}
 
Example #29
Source File: TCKZoneOffsetTransitionRule.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equals_null_false() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(a.equals(null), false);
}
 
Example #30
Source File: TCKTemporalAdjusters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "dayOfWeekInMonth_positive")
public void test_dayOfWeekInMonth_positive(int year, int month, DayOfWeek dow, LocalDate expected) {
    for (int ordinal = 1; ordinal <= 5; ordinal++) {
        for (int day = 1; day <= Month.of(month).length(false); day++) {
            LocalDate date = date(year, month, day);
            LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(ordinal, dow).adjustInto(date);
            assertEquals(test, expected.plusWeeks(ordinal - 1));
        }
    }
}