Example usage for org.joda.time DateTimeZone forTimeZone

List of usage examples for org.joda.time DateTimeZone forTimeZone

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone forTimeZone.

Prototype

public static DateTimeZone forTimeZone(TimeZone zone) 

Source Link

Document

Gets a time zone instance for a JDK TimeZone.

Usage

From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java

License:Open Source License

/**
 * Format the specified date object using the chosen format pattern.
 *///from   www .  jav a  2  s. co m
@Function("DATEFORMAT")
@FunctionParameters({ @FunctionParameter("dateObj"), @FunctionParameter("formatPattern") })
public String DATEFORMAT(Date dateObj, String formatPattern) {
    if (dateObj == null) {
        return null;
    } else {
        DateTimeFormatter formatter = DateTimeFormat.forPattern(formatPattern);
        return new DateTime(dateObj, DateTimeZone.forTimeZone(getReportTimeZone())).toString(formatter);
    }
}

From source file:net.solarnetwork.central.dras.mock.biz.MockDRASObserverBiz.java

License:Open Source License

public MockDRASObserverBiz() {
    TimeZone tz = TimeZone.getTimeZone("Pacific/Auckland");

    uniLocation = new SolarLocation();
    uniLocation.setId(counter.decrementAndGet());
    uniLocation.setCountry("NZ");
    uniLocation.setCreated(new DateTime());
    uniLocation.setName("Mock Location");
    uniLocation.setRegion("UNI");
    uniLocation.setTimeZoneId(tz.getID());
    uniLocation.setLatitude(groupLatitude);
    uniLocation.setLongitude(groupLongitude);

    uniLocations = new LinkedHashMap<Long, SolarLocation>();
    uniLocations.put(uniLocation.getId(), uniLocation);

    uniGroups = new ArrayList<SolarNodeGroup>(numGroups);
    addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group A"));
    addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group B"));
    participantGroups = new ArrayList<CapabilityInformation>(numGroups);
    for (SolarNodeGroup group : uniGroups) {
        SimpleCapabilityInformation groupInfo = new SimpleCapabilityInformation();
        groupInfo.setId(group.getId());/*from  www .j  a v  a  2 s.  c om*/
        groupInfo.setLocation(uniLocation);
        groupInfo.setGenerationCapacityWatts(participantGenerationCapacity);
        groupInfo.setStorageCapacityWattHours(participantStorageCapacity);
        participantGroups.add(groupInfo);
    }

    uniProgramParticipants = new LinkedHashSet<Identity<Long>>(numNodes);
    participantGroupMemebers = new LinkedHashMap<Long, Set<CapabilityInformation>>(numGroups);
    for (int i = 0; i < numNodes; i++) {
        SolarNode participant = new SolarNode(counter.decrementAndGet(), createRandomLocation().getId());
        uniProgramParticipants.add(participant);
        int groupIndex = (i % numGroups);
        SimpleCapabilityInformation group = (SimpleCapabilityInformation) participantGroups.get(groupIndex);
        Set<CapabilityInformation> groupMembers = participantGroupMemebers.get(group.getId());
        if (groupMembers == null) {
            groupMembers = new LinkedHashSet<CapabilityInformation>(numNodes);
            participantGroupMemebers.put(group.getId(), groupMembers);
        }
        SimpleCapabilityInformation info = new SimpleCapabilityInformation();
        info.setId(participant.getId());
        info.setLocation(uniLocations.get(participant.getLocationId()));
        info.setGenerationCapacityWatts(participantGenerationCapacity);
        info.setStorageCapacityWattHours(participantStorageCapacity);
        groupMembers.add(info);
        group.addGenerationCapacityWatts(participantGenerationCapacity);
        group.addStorageCapacityWattHours(participantStorageCapacity);
    }
    uniProgram = new Program(counter.decrementAndGet(), "UNI Program", 1);

    MutableDateTime mdt = new MutableDateTime(2011, 1, 1, 8, 0, 0, 0, DateTimeZone.forTimeZone(tz));
    uniEvents = new ArrayList<Event>(numEvents);
    uniEventParticipants = new LinkedHashMap<Long, EventParticipants>(numEvents);
    uniEventTargets = new LinkedHashMap<Long, EventTargets>(numEvents);

    EventRule eventRule = new EventRule(counter.decrementAndGet(), EventRule.RuleKind.LOAD_AMOUNT,
            EventRule.ScheduleKind.DYNAMIC);
    addEventRule(eventRule);

    for (int i = 0; i < numEvents; i++) {
        Event event = new Event(counter.decrementAndGet(), uniProgram.getId(),
                String.format("Mock Event %d", (i + 1)), mdt.toDateTime(),
                mdt.toDateTime().plus(Period.hours(2)));

        Set<Identity<Long>> groupSet = new LinkedHashSet<Identity<Long>>(2);
        switch (i % 3) {
        case 0:
            groupSet.add(participantGroups.get(0));
            break;

        case 1:
            groupSet.add(participantGroups.get(1));
            break;

        case 2:
            groupSet.add(participantGroups.get(0));
            groupSet.add(participantGroups.get(1));
            break;
        }
        EventParticipants ep = new EventParticipants(counter.decrementAndGet(), event.getId(), null, groupSet);
        uniEventParticipants.put(event.getId(), ep);

        // give each event a load shed target of 1kW
        EventTargets et = new EventTargets(counter.decrementAndGet(), eventRule.getId(),
                new TreeSet<EventTarget>(Arrays.asList(new EventTarget(Duration.ZERO, 1000D))));

        addEvent(event, ep, et);
        mdt.addWeeks(1);
    }
}

From source file:net.solarnetwork.util.JodaBaseJsonDeserializer.java

License:Open Source License

/**
 * Construct from a String date pattern.
 * /*from ww w  .ja  v  a  2  s  .co m*/
 * @param clazz
 *        the class type
 * @param pattern
 *        the Joda date format pattern
 * @param timeZone
 *        the time zone to format in
 */
public JodaBaseJsonDeserializer(Class<T> clazz, String pattern, TimeZone timeZone) {
    super(clazz);
    if (timeZone != null) {
        formatter = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forTimeZone(timeZone));
    } else {
        formatter = DateTimeFormat.forPattern(pattern);
    }
}

From source file:net.solarnetwork.util.JodaBaseJsonSerializer.java

License:Open Source License

/**
 * Construct from a String date pattern.
 * /*from   w  w  w  . ja  va  2  s.  c  o m*/
 * @param clazz
 *        the class type
 * @param pattern
 *        the Joda date format pattern
 * @param timeZone
 *        the time zone to format in
 */
public JodaBaseJsonSerializer(Class<T> clazz, String pattern, TimeZone timeZone) {
    super(clazz);
    if (timeZone != null) {
        formatter = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forTimeZone(timeZone));
    } else {
        formatter = DateTimeFormat.forPattern(pattern);
    }
}

From source file:net.solarnetwork.util.JodaDateFormatEditor.java

License:Open Source License

/**
 * Initialize after properties set.//  ww  w. j  a v  a 2 s .c o  m
 */
public void init() {
    this.dateFormatters = new DateTimeFormatter[this.datePatterns.length];
    for (int i = 0; i < this.dateFormatters.length; i++) {
        this.dateFormatters[i] = DateTimeFormat.forPattern(datePatterns[i]);
        if (timeZone != null) {
            this.dateFormatters[i] = dateFormatters[i].withZone(DateTimeZone.forTimeZone(timeZone));
        }
    }
}

From source file:net.solarnetwork.util.JodaDatePropertySerializer.java

License:Open Source License

/**
 * Construct from a String date pattern.
 * /*from w  w  w . jav  a  2  s.  c  o m*/
 * @param pattern the Joda date format pattern
 * @param timeZone the time zone to format in
 */
public JodaDatePropertySerializer(String pattern, TimeZone timeZone) {
    formatter = DateTimeFormat.forPattern(pattern);
    if (timeZone != null) {
        formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone));
    }
}

From source file:org.activiti.engine.impl.calendar.DurationHelper.java

License:Apache License

private Calendar parseDate(String date) throws Exception {
    return ISODateTimeFormat.dateTimeParser()
            .withZone(DateTimeZone.forTimeZone(clockReader.getCurrentTimeZone())).parseDateTime(date)
            .toCalendar(null);//from  w  w  w.  ja  v  a2 s.c om
}

From source file:org.alfresco.util.ISO8601DateFormat.java

License:Open Source License

/**
 * Parse date from ISO formatted string, either in the specified
 *  TimeZone, or with TimeZone information taken from the date
 * //  ww w  .  j a  va2s.  c  om
 * @param isoDate  ISO string to parse
 * @param timezone The time zone, null means default time zone
 * @return  the date
 * @throws AlfrescoRuntimeException         if the parse failed
 */
public static Date parseInternal(String isoDate, TimeZone timezone) {
    try {
        // null time-zone defaults to the local time-zone
        DateTimeZone dtz = DateTimeZone.forTimeZone(timezone);
        DateTime dateTime = new DateTime(isoDate, dtz);
        Date date = dateTime.toDate();
        return date;
    } catch (IllegalArgumentException e) {
        throw new AlfrescoRuntimeException("Failed to parse date " + isoDate, e);
    }
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

/**
 * Converts the given DateTime to the given TimeZone
 *//*from  w  ww.j ava 2  s.  c  o m*/
public static DateTime toTimeZone(DateTime dt, TimeZone tz) {
    return dt.toDateTime(DateTimeZone.forTimeZone(tz));
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static DateTime now(TimeZone tz) {
    return DateTime.now(DateTimeZone.forTimeZone(tz));
}