List of usage examples for java.time LocalDate getYear
public int getYear()
From source file:org.jc.exercicios.colecoes.eqhc.Associado.java
private static boolean ehAniversario(final LocalDate data, final int ano) { return data.getYear() == ano; }
From source file:com.marklogic.tableauextract.ExtractFromJSON.java
/** * Read JSON output from MarkLogic REST extension or *.xqy file and insert * the output into a Tabeleau table/*from w w w. j ava 2 s . c o m*/ * * @param table * @throws TableauException */ private static void insertData(Table table) throws TableauException, FileNotFoundException, ParseException, IOException { TableDefinition tableDef = table.getTableDefinition(); Row row = new Row(tableDef); URL url = new URL("http://localhost:8060/json.xqy"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream())); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(bufferedReader); JSONArray claims = (JSONArray) jsonObject.get("claims"); @SuppressWarnings("unchecked") Iterator<JSONObject> i = claims.iterator(); while (i.hasNext()) { JSONObject innerObject = i.next(); String idString = (String) innerObject.get("id"); row.setInteger(0, Integer.parseInt(idString.substring(0, 6))); row.setCharString(1, (String) innerObject.get("ssn")); row.setCharString(2, (String) innerObject.get("type")); String payString = (String) innerObject.get("payment_amount"); if (payString == null || payString.isEmpty()) payString = "0.0"; row.setDouble(3, Double.parseDouble(payString)); String dtString = (String) innerObject.get("claim_date"); if (dtString == null || dtString.isEmpty()) dtString = "1999-01-01"; LocalDate claimDate = (LocalDate.parse(dtString)); row.setDate(4, claimDate.getYear(), claimDate.getMonthValue(), claimDate.getDayOfMonth()); table.insert(row); } /* row.setDateTime( 0, 2012, 7, 3, 11, 40, 12, 4550); // Purchased row.setCharString(1, "Beans"); // Product row.setString( 2, "uniBeans"); // uProduct row.setDouble( 3, 1.08); // Price row.setDate( 6, 2029, 1, 1); // Expiration date row.setCharString(7, "Bohnen"); // Produkt for ( int i = 0; i < 10; ++i ) { row.setInteger(4, i * 10); // Quantity row.setBoolean(5, i % 2 == 1); // Taxed } */ }
From source file:ch.algotrader.future.FutureSymbol.java
/** * Generates the RIC for the specified {@link ch.algotrader.entity.security.FutureFamily}. *//*w w w . jav a 2s . co 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 ww w . ja va 2 s . c om 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 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 ww w. java 2s . co m*/ 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:org.vaadin.peholmst.samples.dddwebinar.TestDataGenerator.java
private static LocalDate randomDate(int yearsBack) { LocalDate now = LocalDate.now(); return LocalDate.of(now.getYear() - RND.nextInt(yearsBack), RND.nextInt(12) + 1, RND.nextInt(28) + 1); }
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:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Validate the MultiTypeObject based on the object build with the method * 'buildMultiTypeObject'/* w ww . j a v a2 s. com*/ * * @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:no.imr.stox.functions.utils.CovariateUtils.java
public static Boolean isInPeriod(LocalDate date, String period) { if (date == null || period == null) { return false; }/* w ww . j a v a 2 s . c o m*/ String[] s = period.split("-"); if (s.length == 2) { Integer year = date.getYear(); LocalDate from = IMRdate.strToLocalDate(getFullPeriod(s[0], year), IMRdate.DATE_FORMAT_DMY); LocalDate to = IMRdate.strToLocalDate(getFullPeriod(s[1], year), IMRdate.DATE_FORMAT_DMY); if (IMRdate.isSameDay(date, from) || IMRdate.isSameDay(date, to) || date.isAfter(from) && date.isBefore(to)) { return true; } } return false; }