Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

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

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:org.kzac.common.dto.TimeOfDayInfo.java

License:Educational Community License

/**
 * /*  w w w  .j a v  a2s  .  c om*/
 * @param date
 *            a java.util.Date to which timeOfDay is added (the hours,
 *            minutes, seconds and milliseconds are ignored and treated as
 *            0. Only the month, day, year of date is relevant)
 * @param timeOfDay
 *            the TimeOfDay that is added to the date parameter
 * @return a java.util.Date that is the sum of date and timeOfDay
 */
public static Date getDateWithTimeOfDay(Date date, TimeOfDay timeOfDay) {
    if (date == null || timeOfDay == null) {
        return null;
    }
    // This is JODA which is the preferred way to deal with time.
    // One issue: Java's Date class doesn't have a way to store the timezone
    // associated with the date.
    // Instead, it saves millis since Jan 1, 1970 (GMT), and uses the local
    // machine's timezone to
    // interpret it (although, it can also handle UTC as a timezone). To
    // store the timezone, you either
    // need Joda's LocalDateTime or use the Calendar class. Thus, it is
    // recommended that you either
    // pass in the date relative to the current timezone, or perhaps redo
    // this class where you pass
    // a timezone in, and don't use a Date class, but use a Joda DateTime
    // class. --cclin
    LocalDateTime time = new LocalDateTime(date);
    LocalDateTime result = new LocalDateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(),
            timeOfDay.getHour() == null ? 0 : timeOfDay.getHour(),
            timeOfDay.getMinute() == null ? 0 : timeOfDay.getMinute(),
            timeOfDay.getSecond() == null ? 0 : timeOfDay.getSecond(), 0);
    return result.toDateTime().toDate();
}

From source file:org.mifosplatform.infrastructure.reportmailingjob.domain.ReportMailingJob.java

License:Mozilla Public License

/** 
 * Update the ReportMailingJob entity /*from  w  w w .  jav  a2 s .  c o  m*/
 * 
 * @param jsonCommand JsonCommand object
 * @return map of string to object
 **/
public Map<String, Object> update(final JsonCommand jsonCommand) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME, this.name)) {
        final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.NAME_PARAM_NAME, name);

        this.name = name;
    }

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.DESCRIPTION_PARAM_NAME,
            this.description)) {
        final String description = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.DESCRIPTION_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.DESCRIPTION_PARAM_NAME, description);

        this.description = description;
    }

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.RECURRENCE_PARAM_NAME,
            this.recurrence)) {
        final String recurrence = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.RECURRENCE_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.RECURRENCE_PARAM_NAME, recurrence);

        this.recurrence = recurrence;
    }

    if (jsonCommand.isChangeInBooleanParameterNamed(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME,
            this.isActive)) {
        final boolean isActive = jsonCommand
                .booleanPrimitiveValueOfParameterNamed(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME, isActive);

        this.isActive = isActive;
    }

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME,
            this.emailRecipients)) {
        final String emailRecipients = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME, emailRecipients);

        this.emailRecipients = emailRecipients;
    }

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME,
            this.emailSubject)) {
        final String emailSubject = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME, emailSubject);

        this.emailSubject = emailSubject;
    }

    if (jsonCommand.isChangeInStringParameterNamed(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME,
            this.emailMessage)) {
        final String emailMessage = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME, emailMessage);

        this.emailMessage = emailMessage;
    }

    if (jsonCommand.isChangeInStringParameterNamed(
            ReportMailingJobConstants.STRETCHY_REPORT_PARAM_MAP_PARAM_NAME, this.stretchyReportParamMap)) {
        final String stretchyReportParamMap = jsonCommand
                .stringValueOfParameterNamed(ReportMailingJobConstants.STRETCHY_REPORT_PARAM_MAP_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.STRETCHY_REPORT_PARAM_MAP_PARAM_NAME,
                stretchyReportParamMap);

        this.stretchyReportParamMap = stretchyReportParamMap;
    }

    final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat = ReportMailingJobEmailAttachmentFileFormat
            .instance(this.emailAttachmentFileFormat);

    if (jsonCommand.isChangeInIntegerParameterNamed(
            ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME,
            emailAttachmentFileFormat.getId())) {
        final Integer emailAttachmentFileFormatId = jsonCommand.integerValueOfParameterNamed(
                ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME,
                emailAttachmentFileFormatId);

        final ReportMailingJobEmailAttachmentFileFormat newEmailAttachmentFileFormat = ReportMailingJobEmailAttachmentFileFormat
                .instance(emailAttachmentFileFormatId);
        this.emailAttachmentFileFormat = newEmailAttachmentFileFormat.getValue();
    }

    final String newStartDateTimeString = jsonCommand
            .stringValueOfParameterNamed(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME);

    if (!StringUtils.isEmpty(newStartDateTimeString)) {
        final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());
        final LocalDateTime newStartDateTime = LocalDateTime.parse(newStartDateTimeString, dateTimeFormatter);
        final LocalDateTime oldStartDateTime = (this.startDateTime != null)
                ? new LocalDateTime(this.startDateTime)
                : null;

        if ((oldStartDateTime != null) && !newStartDateTime.equals(oldStartDateTime)) {
            actualChanges.put(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME, newStartDateTimeString);

            this.startDateTime = newStartDateTime.toDate();
        }
    }

    Long currentStretchyReportId = null;

    if (this.stretchyReport != null) {
        currentStretchyReportId = this.stretchyReport.getId();
    }

    if (jsonCommand.isChangeInLongParameterNamed(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME,
            currentStretchyReportId)) {
        final Long updatedStretchyReportId = jsonCommand
                .longValueOfParameterNamed(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME);
        actualChanges.put(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME, updatedStretchyReportId);
    }

    return actualChanges;
}

From source file:org.odk.collect.android.widgets.AbstractDateWidget.java

License:Apache License

protected void createWidget() {
    datePickerDetails = DateTimeUtils//ww  w  . j a va  2  s  .co m
            .getDatePickerDetails(getFormEntryPrompt().getQuestion().getAppearanceAttr());
    createDateButton();
    dateTextView = getAnswerTextView();
    addViews();
    if (getFormEntryPrompt().getAnswerValue() == null) {
        clearAnswer();
        setDateToCurrent();
    } else {
        date = new LocalDateTime(getFormEntryPrompt().getAnswerValue().getValue());
        setDateLabel();
    }
}

From source file:org.onosproject.cli.MetricsListCommand.java

License:Apache License

/**
 * Print metric object.//from   w  w w  . ja v a2 s  .c o  m
 *
 * @param name metric name
 * @param metric metric object
 */
private void printMetric(String name, Metric metric) {
    final String heading;

    if (metric instanceof Counter) {
        heading = format("-- %s : [%s] --", name, "Counter");
        print(heading);
        Counter counter = (Counter) metric;
        print("          count = %d", counter.getCount());

    } else if (metric instanceof Gauge) {
        heading = format("-- %s : [%s] --", name, "Gauge");
        print(heading);
        @SuppressWarnings("rawtypes")
        Gauge gauge = (Gauge) metric;
        final Object value = gauge.getValue();
        if (name.endsWith("EpochMs") && value instanceof Long) {
            print("          value = %s (%s)", value, new LocalDateTime(value));
        } else {
            print("          value = %s", value);
        }

    } else if (metric instanceof Histogram) {
        heading = format("-- %s : [%s] --", name, "Histogram");
        print(heading);
        final Histogram histogram = (Histogram) metric;
        final Snapshot snapshot = histogram.getSnapshot();
        print("          count = %d", histogram.getCount());
        print("            min = %d", snapshot.getMin());
        print("            max = %d", snapshot.getMax());
        print("           mean = %f", snapshot.getMean());
        print("         stddev = %f", snapshot.getStdDev());

    } else if (metric instanceof Meter) {
        heading = format("-- %s : [%s] --", name, "Meter");
        print(heading);
        final Meter meter = (Meter) metric;
        print("          count = %d", meter.getCount());
        print("      mean rate = %f", meter.getMeanRate());
        print("  1-minute rate = %f", meter.getOneMinuteRate());
        print("  5-minute rate = %f", meter.getFiveMinuteRate());
        print(" 15-minute rate = %f", meter.getFifteenMinuteRate());

    } else if (metric instanceof Timer) {
        heading = format("-- %s : [%s] --", name, "Timer");
        print(heading);
        final Timer timer = (Timer) metric;
        final Snapshot snapshot = timer.getSnapshot();
        print("          count = %d", timer.getCount());
        print("      mean rate = %f per second", timer.getMeanRate());
        print("  1-minute rate = %f per second", timer.getOneMinuteRate());
        print("  5-minute rate = %f per second", timer.getFiveMinuteRate());
        print(" 15-minute rate = %f per second", timer.getFifteenMinuteRate());
        print("            min = %f ms", nanoToMs(snapshot.getMin()));
        print("            max = %f ms", nanoToMs(snapshot.getMax()));
        print("           mean = %f ms", nanoToMs(snapshot.getMean()));
        print("         stddev = %f ms", nanoToMs(snapshot.getStdDev()));
    } else {
        heading = format("-- %s : [%s] --", name, metric.getClass().getCanonicalName());
        print(heading);
        print("Unknown Metric type:{}", metric.getClass().getCanonicalName());
    }
    print(Strings.repeat("-", heading.length()));
}

From source file:org.onosproject.event.AbstractEvent.java

License:Apache License

@Override
public String toString() {
    return toStringHelper(this).add("time", new LocalDateTime(time)).add("type", type())
            .add("subject", subject()).toString();
}

From source file:org.onosproject.events.EventsCommand.java

License:Apache License

private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
        DeviceEvent deviceEvent = (DeviceEvent) event;
        if (event.type().toString().startsWith("PORT")) {
            // Port event
            print("%s %s\t%s/%s [%s]", new LocalDateTime(event.time()), event.type(),
                    deviceEvent.subject().id(), deviceEvent.port().number(), deviceEvent.port());
        } else {//from ww  w.  j  a v  a 2 s  . c  o  m
            // Device event
            print("%s %s\t%s [%s]", new LocalDateTime(event.time()), event.type(), deviceEvent.subject().id(),
                    deviceEvent.subject());
        }

    } else if (event instanceof MastershipEvent) {
        print("%s %s\t%s [%s]", new LocalDateTime(event.time()), event.type(), event.subject(),
                ((MastershipEvent) event).roleInfo());

    } else if (event instanceof LinkEvent) {
        LinkEvent linkEvent = (LinkEvent) event;
        Link link = linkEvent.subject();
        print("%s %s\t%s/%s-%s/%s [%s]", new LocalDateTime(event.time()), event.type(), link.src().deviceId(),
                link.src().port(), link.dst().deviceId(), link.dst().port(), link);

    } else if (event instanceof HostEvent) {
        HostEvent hostEvent = (HostEvent) event;
        print("%s %s\t%s [%s->%s]", new LocalDateTime(event.time()), event.type(), hostEvent.subject().id(),
                hostEvent.prevSubject(), hostEvent.subject());

    } else if (event instanceof TopologyEvent) {
        TopologyEvent topoEvent = (TopologyEvent) event;
        List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
        Topology topo = topoEvent.subject();
        String summary = String.format("(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(),
                topo.clusterCount());
        print("%s %s%s [%s]", new LocalDateTime(event.time()), event.type(), summary,
                reasons.stream().map(e -> e.type()).collect(toList()));

    } else if (event instanceof ClusterEvent) {
        print("%s %s\t%s [%s]", new LocalDateTime(event.time()), event.type(),
                ((ClusterEvent) event).subject().id(), event.subject());

    } else {
        // Unknown Event?
        print("%s %s\t%s [%s]", new LocalDateTime(event.time()), event.type(), event.subject(), event);
    }
}

From source file:org.onosproject.evpnrouteservice.EvpnRouteEvent.java

License:Apache License

@Override
public String toString() {
    return toStringHelper(this).add("time", new LocalDateTime(time())).add("type", type())
            .add("subject", subject()).add("prevSubject", prevSubject).add("alternatives", alternativeRoutes)
            .toString();//from   w ww. j a v a  2  s  .com
}

From source file:org.onosproject.incubator.net.intf.InterfaceEvent.java

License:Apache License

@Override
public String toString() {
    if (prevSubject == null) {
        return super.toString();
    }//from w  w w.ja  va  2 s.co  m
    return toStringHelper(this).add("time", new LocalDateTime(time())).add("type", type())
            .add("subject", subject()).add("prevSubject", prevSubject).toString();
}

From source file:org.onosproject.incubator.net.routing.RouteEvent.java

License:Apache License

@Override
public String toString() {
    return toStringHelper(this).add("time", new LocalDateTime(time())).add("type", type())
            .add("subject", subject()).add("prevSubject", prevSubject()).toString();
}

From source file:org.onosproject.iptopology.api.device.IpDeviceEvent.java

License:Apache License

@Override
public String toString() {
    if (devInterface == null || devicePrefix == null) {
        return super.toString();
    }/*w w  w.  ja  v a  2  s. c  o  m*/
    return toStringHelper(this).add("time", new LocalDateTime(time())).add("type", type())
            .add("subject", subject()).add("interface", devInterface).add("prefix", devicePrefix).toString();
}