List of usage examples for org.joda.time Instant get
public int get(DateTimeFieldType type)
From source file:org.chaston.oakfunds.model.ModelManagerImpl.java
License:Apache License
private void recalculateAccountTransactions(Model model, Account account, Instant start, Instant end) throws StorageException { List<? extends SearchTerm> searchTerms = ImmutableList .of(AttributeSearchTerm.of(ModelBound.ATTRIBUTE_MODEL_ID, SearchOperator.EQUALS, model.getId())); Iterable<RecurringEvent> recurringEvents = store.findIntervalRecords(account, RecurringEvent.TYPE, start, end, searchTerms);/*from w w w.j a v a 2 s.c o m*/ for (RecurringEvent recurringEvent : recurringEvents) { if (recurringEvent instanceof MonthlyRecurringEvent) { Map<String, Object> attributes = new HashMap<>(); attributes.put(ModelBound.ATTRIBUTE_MODEL_ID, model.getId()); attributes.put(ModelAccountTransaction.ATTRIBUTE_AMOUNT, recurringEvent.getAmount()); attributes.put(ModelAccountTransaction.ATTRIBUTE_DERIVED, true); for (Instant instant : getAllInstantsInRange(recurringEvent.getStart(), recurringEvent.getEnd())) { ModelAccountTransaction accountTransaction = store.insertInstantRecord(account, ModelAccountTransaction.TYPE, instant, attributes); createCompensatingAccountTransaction(account, accountTransaction, attributes); } } if (recurringEvent instanceof AnnualRecurringEvent) { AnnualRecurringEvent annualRecurringEvent = (AnnualRecurringEvent) recurringEvent; Map<String, Object> attributes = new HashMap<>(); attributes.put(ModelBound.ATTRIBUTE_MODEL_ID, model.getId()); attributes.put(ModelAccountTransaction.ATTRIBUTE_AMOUNT, recurringEvent.getAmount()); attributes.put(ModelAccountTransaction.ATTRIBUTE_DERIVED, true); attributes.put(ModelAccountTransaction.ATTRIBUTE_DISTRIBUTION_TIME, 1); attributes.put(ModelAccountTransaction.ATTRIBUTE_DISTRIBUTION_TIME_UNIT, DistributionTimeUnit.YEARS); for (Instant instant : getAllInstantsInRange(recurringEvent.getStart(), recurringEvent.getEnd())) { if (instant.get(DateTimeFieldType.monthOfYear()) == annualRecurringEvent.getPaymentMonth()) { ModelAccountTransaction accountTransaction = store.insertInstantRecord(account, ModelAccountTransaction.TYPE, instant, attributes); recalculateDistributionTransactions(model, account, accountTransaction); ModelAccountTransaction compensatingAccountTransaction = createCompensatingAccountTransaction( account, accountTransaction, attributes); if (compensatingAccountTransaction != null) { recalculateDistributionTransactions(model, account, compensatingAccountTransaction); } } } } } }
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Given an instant, return the time within one day that it represents as a string. * //www . j av a 2 s . c o m * @param instant to obtain time from. * @return string in the form hh:mm:ss.sssZ or an empty string if instant is null. */ protected static String instantToStringTime(Instant instant) { String result = ""; if (instant != null) { StringBuffer time = new StringBuffer(); time.append(String.format("%02d", instant.get(DateTimeFieldType.hourOfDay()))); time.append(":").append(String.format("%02d", instant.get(DateTimeFieldType.minuteOfHour()))); time.append(":").append(String.format("%02d", instant.get(DateTimeFieldType.secondOfMinute()))); time.append(".").append(String.format("%03d", instant.get(DateTimeFieldType.millisOfSecond()))); String timeZone = instant.getZone().getID(); if (timeZone.equals("UTC")) { time.append("Z"); } else { time.append(timeZone); } result = time.toString(); } return result; }
From source file:org.powertac.customer.model.LiftTruck.java
License:Apache License
int indexOfShift(Instant time) { int hour = time.get(DateTimeFieldType.hourOfDay()); int day = time.get(DateTimeFieldType.dayOfWeek()); return hour + (day - 1) * HOURS_DAY; }
From source file:org.powertac.customer.model.LiftTruck.java
License:Apache License
private Instant getNextSunday() { Instant result = getNowInstant(); int hour = result.get(DateTimeFieldType.hourOfDay()); if (hour > 0) result = result.plus((24 - hour) * TimeService.HOUR); int day = result.get(DateTimeFieldType.dayOfWeek()); result = result.plus((7 - day) * TimeService.DAY); return result; }
From source file:org.powertac.logtool.example.ProductionConsumption.java
License:Apache License
private void summarizeTimeslot(Instant instant) { if (!dataInit) { // first time through nothing to but print header //data.println("slot, dow, hour, production, consumption"); if (byBroker) { gameId = Competition.currentCompetition().getName(); brokerUsed = new HashMap<Broker, Double>(); brokerProduced = new HashMap<Broker, Double>(); BrokerRepo brokerRepo = (BrokerRepo) getBean("brokerRepo"); for (Broker broker : brokerRepo.findRetailBrokers()) { brokerUsed.put(broker, 0.0); brokerProduced.put(broker, 0.0); }/*from w w w . jav a 2 s . c o m*/ } dataInit = true; return; } // output format depends on options if (byBroker) { // print game-id, timeslot, broker-name, production, consumption for (Broker broker : brokerUsed.keySet()) { data.print(String.format("%s, %d, %s, ", gameId, timeslot, broker.getUsername())); data.println(String.format("%.3f, %.3f", brokerProduced.get(broker), brokerUsed.get(broker))); brokerProduced.put(broker, 0.0); brokerUsed.put(broker, 0.0); } } else { // print timeslot, dow, hod, production, consumption data.print(String.format("%d, %d, %d, ", timeslot, instant.get(DateTimeFieldType.dayOfWeek()), instant.get(DateTimeFieldType.hourOfDay()))); // print customer usage, production data.println(String.format("%.3f, %.3f", produced, used)); produced = 0.0; used = 0.0; } }
From source file:org.powertac.logtool.example.SolarProduction.java
License:Apache License
private void summarizeTimeslot(Instant instant) { if (!dataInit) { // first time through -- extract the list of solar customers for (CustomerInfo info : customerRepo.list()) { if (info.getPowerType() == PowerType.SOLAR_PRODUCTION) solarCustomers.add(info); }/*from w w w.j ava 2s . com*/ dataInit = true; return; } // print timeslot index and dow data.print(String.format("%d, %d, %d, ", timeslot, instant.get(DateTimeFieldType.dayOfWeek()), instant.get(DateTimeFieldType.hourOfDay()))); // print customer usage, production data.println(String.format("%.3f, %.3f", produced, 0.0)); produced = 0.0; }