List of usage examples for org.joda.time Instant toDateTime
public DateTime toDateTime()
From source file:org.joda.example.time.Examples.java
License:Apache License
private void runInstant() { System.out.println("Instant"); System.out.println("======="); System.out/*from w w w.j a va2s . c om*/ .println("Instant stores a point in the datetime continuum as millisecs from 1970-01-01T00:00:00Z"); System.out.println("Instant is immutable and thread-safe"); System.out.println(" in = new Instant()"); Instant in = new Instant(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("UTC time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println(""); System.out.println(" in2 = new Instant(in.getMillis() + 10)"); Instant in2 = new Instant(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }
From source file:org.n52.shetland.ogc.gml.time.TimeInstant.java
License:Apache License
/** * Creates a new {@code TimeInstant}./*from ww w. j a va2 s. co m*/ * * @param instant the instant */ public TimeInstant(Instant instant) { this(instant != null ? instant.toDateTime() : null, 0, null); }
From source file:org.powertac.common.TariffEvaluationHelper.java
License:Apache License
/** * Estimate the total cost of buying the given amounts of power * from the given tariff, starting in the timeslot identified by startIndex. * Payments include usage charges, and periodic payments just in case * <code>includePeriodicCharge</code> is true. They do not * include signup or withdrawal charges. * Note that there is a strong assumption that the projected usage * is for a single customer, not the total population in some model. * This assumption is embedded in the structure of usage tiers in the * tariff./* w w w .j av a 2 s.c o m*/ */ public double estimateCost(Tariff tariff, double[] usage, Instant start, boolean includePeriodicCharge) { init(); this.tariff = tariff; computeAlpha(tariff); double dailyUsage = 0.0; double result = 0.0; //Instant time = timeService.getCurrentTime(); Instant time = start; if (null == time) log.error("Time is null!"); for (int index = 0; index < usage.length; index++) { time = time.plus(TimeService.HOUR); result += tariff.getUsageCharge(time, usage[index], dailyUsage, this); if (includePeriodicCharge) result += tariff.getPeriodicPayment() / 24.0; if (time.toDateTime().getHourOfDay() == 0) { //reset the daily usage counter dailyUsage = 0.0; } else { dailyUsage += usage[index]; } } // Account for regulation. In general, customers get paid (+) for up-reg // and must pay (-) for down. Also, in general, the amounts are positive // for up-reg and negative for down-reg. This explains the signs used here. double adj = 0.0; if (tariff.hasRegulationRate()) { double upreg = (expCurtail + expDischarge) * tariff.overpricedUpRegulationRatio(); adj += tariff.getRegulationCharge(upreg, 0.0, false); double downreg = expDown * tariff.overpricedDownRegulationRatio(); adj += tariff.getRegulationCharge(downreg, 0.0, false); // Extra burden for tariffs with higher cost for down-regulation // than for consumption } return result + adj * usage.length; }