List of usage examples for java.time LocalDate getMonth
public Month getMonth()
From source file:cz.pichlik.goodsentiment.MockDataGenerator.java
public static LocalDateTime generateTimestamp(LocalDate seed) { return of(seed.getYear(), seed.getMonth(), seed.getDayOfMonth(), 0, 0).plusHours(rg().nextInt(23)) .plusMinutes(rg().nextInt(59)).plusSeconds(rg().nextInt(59)); }
From source file:ch.algotrader.future.FutureSymbol.java
/** * Generates the RIC for the specified {@link ch.algotrader.entity.security.FutureFamily}. *//*w w w. j a v a2 s .c o m*/ public static String getRic(SecurityFamily family, LocalDate expiration) { Month month = expiration.getMonth(); int year = expiration.getYear(); ; StringBuilder buffer = new StringBuilder(); buffer.append(family.getRicRoot() != null ? family.getRicRoot() : family.getSymbolRoot()); buffer.append(monthEnc[month.getValue() - 1]); buffer.append(String.valueOf(year).substring(3)); buffer.append(":VE"); return buffer.toString(); }
From source file:ch.algotrader.future.FutureSymbol.java
/** * Generates the ISIN for the specified {@link ch.algotrader.entity.security.FutureFamily}. *///from www . j a va 2 s .c o m public static String getIsin(SecurityFamily family, LocalDate expiration) { int week = 0; Month month = expiration.getMonth(); int year = expiration.getYear(); ; StringBuilder buffer = new StringBuilder(); buffer.append(week); buffer.append("F"); buffer.append(family.getIsinRoot() != null ? family.getIsinRoot() : family.getSymbolRoot()); buffer.append(monthEnc[month.getValue() - 1]); buffer.append(yearEnc[year % 10]); buffer.append("00000"); return buffer.toString(); }
From source file:com.github.drbookings.LocalDates.java
public static boolean isCurrentMonth(final LocalDate date) { final Month month = LocalDate.now().getMonth(); return date.getMonth().equals(month) && date.getYear() == LocalDate.now().getYear(); }
From source file:com.github.drbookings.LocalDates.java
public static boolean isLastMonth(final LocalDate date) { final Month month = LocalDate.now().getMonth().minus(1); return date.getMonth().equals(month) && (date.getYear() == LocalDate.now().getYear() || date.getYear() == LocalDate.now().getYear() - 1); }
From source file:com.github.drbookings.LocalDates.java
public static boolean isLastThreeMonths(final LocalDate date) { final Month month = LocalDate.now().getMonth().minus(1); if (date.getMonth().equals(month) && (date.getYear() == LocalDate.now().getYear() || date.getYear() == LocalDate.now().getYear() - 1)) { return true; }//from w ww .j av a 2s . com if (date.getMonth().equals(month.minus(1)) && (date.getYear() == LocalDate.now().getYear() || date.getYear() == LocalDate.now().getYear() - 1)) { return true; } return date.getMonth().equals(month.minus(2)) && (date.getYear() == LocalDate.now().getYear() || date.getYear() == LocalDate.now().getYear() - 1); }
From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Validate the MultiTypeObject based on the object build with the method * 'buildMultiTypeObject'// w w w. jav a2 s. co m * * @param toValidate * the object to validate */ public static void validateMultiTypeObject(MultiTypeObject toValidate) { MultiTypeObject base = buildMultiTypeObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); LocalDate localDate = LocalDate.now(); assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth()); assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth()); assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear()); LocalDateTime localDateTime = LocalDateTime.now(); assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth()); assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth()); assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear()); assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour()); /* it is possible to have an error below due the time of execution of the test */ assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute()); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress()); assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber()); assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity()); assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode()); assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); assertEquals(base.getShortAttribute(), toValidate.getShortAttribute()); assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute()); // TODO add new validation below }
From source file:ch.algotrader.future.FutureSymbol.java
/** * Generates the symbol for the specified {@link ch.algotrader.entity.security.FutureFamily}. * * Example//w w w. ja v a2 s .com * <table> * <tr><td><b>Pattern</b></td><td><b>Description</b></td><td><b>Example</b></td></tr> * <tr><td>N</td><td>Name</td><td>CrudeOil</td></tr> * <tr><td>CR</td><td>SymbolRoot</td><td>CL</td></tr> * <tr><td>C</td><td>Currency</td><td>USD</td></tr> * <tr><td>CS</td><td>ContractSize</td><td>1000</td></tr> * <tr><td>M</td><td>Month 1-digit</td><td>6</td></tr> * <tr><td>MM</td><td>Month 2-digit</td><td>06</td></tr> * <tr><td>MMM</td><td>Month Short</td><td>JUN</td></tr> * <tr><td>MMMM</td><td>Month Long</td><td>June</td></tr> * <tr><td>YY</td><td>Year 2-digit</td><td>16</td></tr> * <tr><td>YYYY</td><td>Year 4-digit</td><td>2016</td></tr> * </table> */ public static String getSymbol(SecurityFamily family, LocalDate expiration, String pattern) { String[] placeHolders = new String[] { "N", "SR", "CS", "C", "MMMM", "MMM", "MM", "MR", "YYYY", "YY", "YR" }; String[] values = new String[] { family.getName(), family.getSymbolRoot(), RoundUtil.getBigDecimal(family.getContractSize(), 0).toString(), family.getCurrency().toString(), DateTimePatterns.MONTH_LONG.format(expiration).toUpperCase(), DateTimePatterns.MONTH_SHORT.format(expiration).toUpperCase(), DateTimePatterns.MONTH_2_DIGIT.format(expiration).toUpperCase(), monthEnc[expiration.getMonth().getValue() - 1], DateTimePatterns.YEAR_4_DIGIT.format(expiration), DateTimePatterns.YEAR_2_DIGIT.format(expiration), yearEnc[expiration.getYear() % 10] }; return StringUtils.replaceEach(pattern, placeHolders, values); }
From source file:ch.algotrader.option.OptionSymbol.java
/** * Generates the symbole for the specified {@link ch.algotrader.entity.security.OptionFamily}. * * Example// w ww. j ava 2s . co m * <table> * <tr><td><b>Pattern</b></td><td><b>Description</b></td><td><b>Example</b></td></tr> * <tr><td>N</td><td>Name</td><td>CrudeOil</td></tr> * <tr><td>CR</td><td>SymbolRoot</td><td>CL</td></tr> * <tr><td>C</td><td>Currency</td><td>USD</td></tr> * <tr><td>CS</td><td>ContractSize</td><td>1000</td></tr> * <tr><td>M</td><td>Month 1-digit</td><td>6</td></tr> * <tr><td>MM</td><td>Month 2-digit</td><td>06</td></tr> * <tr><td>MMM</td><td>Month Short</td><td>JUN</td></tr> * <tr><td>MMMM</td><td>Month Long</td><td>June</td></tr> * <tr><td>YY</td><td>Year 2-digit</td><td>16</td></tr> * <tr><td>YYYY</td><td>Year 4-digit</td><td>2016</td></tr> * <tr><td>W</td><td>Week of Month</td><td>3</td></tr> * <tr><td>T</td><td>Type Short</td><td>C</td></tr> * <tr><td>TT</td><td>Type Long</td><td>CALL</td></tr> * <tr><td>S</td><td>Strike</td><td>500</td></tr> * </table> */ public static String getSymbol(OptionFamily family, LocalDate expiration, OptionType type, BigDecimal strike, String pattern) { String[] placeHolders = new String[] { "N", "SR", "CS", "C", "MMMM", "MMM", "MM", "MR", "YYYY", "YY", "YR", "W", "TT", "T", "S" }; String[] values = new String[] { family.getName(), family.getSymbolRoot(), RoundUtil.getBigDecimal(family.getContractSize(), 0).toString(), family.getCurrency().toString(), DateTimePatterns.MONTH_LONG.format(expiration).toUpperCase(), DateTimePatterns.MONTH_SHORT.format(expiration).toUpperCase(), DateTimePatterns.MONTH_2_DIGIT.format(expiration).toUpperCase(), OptionType.CALL.equals(type) ? monthCallEnc[expiration.getMonth().getValue() - 1] : monthPutEnc[expiration.getMonthValue() - 1], DateTimePatterns.YEAR_4_DIGIT.format(expiration), DateTimePatterns.YEAR_2_DIGIT.format(expiration), yearEnc[expiration.getYear() % 10], DateTimePatterns.WEEK_OF_MONTH.format(expiration), type.toString(), type.toString().substring(0, 1), strike.toString() }; return StringUtils.replaceEach(pattern, placeHolders, values); }
From source file:io.sqp.core.types.SqpDateTest.java
@Test(dataProvider = "dateValues") public void CanDecodeFromJson(byte[] content, DataFormat format) throws Exception { ObjectMapper mapper = JacksonObjectMapperFactory.objectMapper(format); Object dateObj = mapper.readValue(content, Object.class); SqpDate sqpDate = SqpDate.fromJsonFormatValue(dateObj); LocalDate localDate = sqpDate.asLocalDate(); assertThat(localDate.getYear(), is(2015)); assertThat(localDate.getMonth(), is(Month.JUNE)); assertThat(localDate.getDayOfMonth(), is(28)); }