Example usage for org.joda.time LocalDateTime toDate

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

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.sam.moca.server.expression.operators.arith.PlusExpression.java

License:Open Source License

private MocaValue addToDate(MocaValue date, MocaValue days) {
    Date d = date.asDate();/*w ww.j  a  v  a2 s .co m*/

    // If the left side is null, return a null result.
    if (d == null) {
        return new MocaValue(MocaType.DATETIME, null);
    }

    MocaType daysType = days.getType();
    if (daysType == MocaType.INTEGER || daysType == MocaType.DOUBLE) {
        LocalDateTime dt = new LocalDateTime(d);

        int wholeDays = days.asInt();
        double dayPart = days.asDouble() - wholeDays;
        int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0);

        dt = dt.plusDays(wholeDays).plusMillis(msDiff);

        return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate());
    } else {
        return date;
    }
}

From source file:com.trifork.stamdata.importer.jobs.cpr.CPRParser.java

License:Mozilla Public License

private static Date parseDateAndCheckValidity(String dateString, DateTimeFormatter format, String line)
        throws ParseException, Exception {
    dateString = fixWeirdDate(dateString);
    LocalDateTime date = format.parseLocalDateTime(dateString);
    String formattedDate = format.print(date);

    if (!formattedDate.equals(dateString)) {
        String errorMessage = "Ugyldig dato: " + dateString + " fra linjen [" + line + "]";

        if (haltOnDateErrors) {
            throw new Exception(errorMessage);
        } else {//from w  ww.ja  v  a2  s  .  c  o  m
            logger.error(errorMessage);
        }
    }

    return date.toDate();
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.java

License:Open Source License

private void setLatestResourceValues(Map<String, Object> rowMap, List<String> tagHeaders,
        AwsResourceDetailDto resourceDetail) {
    LocalDateTime usageStartTimeFromCsv = (LocalDateTime) rowMap.get(DetailedCsvHeaders.USAGE_START_DATE);
    LocalDateTime existingUsageStartTime = null;
    if (resourceDetail.usageStartTime != null) {
        existingUsageStartTime = new LocalDateTime(resourceDetail.usageStartTime);
    }/* w  ww  .ja  va2  s . c o  m*/
    if (existingUsageStartTime == null || existingUsageStartTime.compareTo(usageStartTimeFromCsv) <= 0) {
        resourceDetail.itemDescription = getStringFieldValue(rowMap, DetailedCsvHeaders.ITEM_DESCRIPTION);
        resourceDetail.usageStartTime = usageStartTimeFromCsv.toDate().getTime();
        resourceDetail.tags = getTagsForResources(rowMap, tagHeaders);
        boolean isRowMarkedAsReserved = convertReservedInstance(
                getStringFieldValue(rowMap, DetailedCsvHeaders.IS_RESERVED_INSTANCE));
        boolean isResourceReservedForThisHour;
        Long millisForBillDay = getMillisForHour(usageStartTimeFromCsv);
        if (existingUsageStartTime != null && existingUsageStartTime.isEqual(usageStartTimeFromCsv)) {
            isResourceReservedForThisHour = resourceDetail.isReservedInstance || isRowMarkedAsReserved;
            if (isRowMarkedAsReserved && !resourceDetail.isReservedInstance) {
                resourceDetail.addToHoursAsReservedPerDay(millisForBillDay, 1.0);
            }
        } else {
            isResourceReservedForThisHour = isRowMarkedAsReserved;
            if (isResourceReservedForThisHour) {
                resourceDetail.addToHoursAsReservedPerDay(millisForBillDay, 1.0);
            }
        }
        resourceDetail.isReservedInstance = isResourceReservedForThisHour;
    }
}

From source file:control.ConfigController.java

public static String getLastBackupDate() {
    dao = new GenericDAO();
    String s = dao.get("app_config", "last_backup");
    LocalDateTime ldt = new LocalDateTime(s);
    s = "" + ldt.toDate().toLocaleString() + "";
    return s;//from w ww.  j a v  a 2 s .co m
}

From source file:de.hh.changeRing.infrastructure.eclipselink.JodaLocalDateTimeConverter.java

License:Open Source License

@Override
public java.util.Date toDatabaseLayerType(org.joda.time.LocalDateTime objectValue) {
    return objectValue.toDateTime().toDate();
}

From source file:de.jpaw.bonaparte.poi.BaseExcelComposer.java

License:Apache License

@Override
public void addField(TemporalElementaryDataItem di, LocalDateTime t) {
    if (t != null) {
        newCell(di, csTimestamp).setCellValue(t.toDate());
    } else {/*w  w  w  .  j a  v a 2s  .  c  om*/
        writeNull(di);
    }
}

From source file:de.jpaw.bonaparte.util.DayTime.java

License:Apache License

/** Provides functionality to convert a Joda timestamp to a GregorianCalendar. */
static public GregorianCalendar toCalendar(LocalDateTime when) {
    if (when == null) {
        return null;
    }//from  w  w w .  j  a va 2 s  .com
    GregorianCalendar then = new GregorianCalendar();
    then.setTime(when.toDate());
    return then;
}

From source file:de.jpaw.bonaparte.util.DayTime.java

License:Apache License

/** Provides functionality to convert a Joda timestamp to a java Date. */
static public Date toDate(LocalDateTime when) {
    if (when == null) {
        return null;
    }//from  ww w .  j a v  a2s .  co m
    return when.toDate();
}

From source file:edu.sampleu.demo.kitchensink.UifComponentsTestForm.java

License:Educational Community License

public UifComponentsTestForm() {
    super();//from  w  ww.j  av  a  2 s.co m

    uiTestObject = new UITestObject("Foo", "FooBar", "FooBear", "FooRacket");

    sourceCodeField = "&lt;bean parent=\"Uif-PrimaryActionButton\" p:actionLabel=\"Save\" p:methodToCall=\"performSave\"&gt;\n"
            + "&#32;&#32;&lt;property name=\"actionImage\"&gt;\n"
            + "&#32;&#32;&#32;&#32;&lt;bean parent=\"Uif-Image\"\n"
            + "&#32;&#32;&#32;&#32;&#32;&#32;p:source=\"@{#ConfigProperties['krad.externalizable.images.url']}searchicon.png\"\n"
            + "&#32;&#32;&#32;&#32;&#32;&#32;p:actionImageLocation=\"RIGHT\"/&gt;\n"
            + "&#32;&#32;&lt;/property&gt;\n" + "&lt;/bean&gt;";

    list1.add(new UITestObject("5", "6", "7", "8", new UITestObject("1", "1", "1", "1")));
    UITestObject obj1 = new UITestObject("1", "2", "3", "4", new UITestObject("1", "1", "1", "1"));
    obj1.setStringList(null);
    list1.add(obj1);
    UITestObject obj2 = new UITestObject("9", "10", "11", "12", new UITestObject("1", "1", "1", "1"));
    obj2.setStringList(new ArrayList<String>());
    list1.add(obj2);
    list1.add(new UITestObject("13", "14", "15", "16", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("17", "18", "19", "20", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("52", "6", "7", "8", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("12", "2", "3", "4", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("92", "10", "11", "12", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("132", "14", "15", "16", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("2132", "143", "151", "126", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("1332", "144", "155", "156", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("2132", "143", "151", "126", new UITestObject("1", "1", "1", "1")));
    list1.add(new UITestObject("1332", "144", "155", "156", new UITestObject("1", "1", "1", "1")));

    list2.add(new UITestObject("A", "B", "C", "D"));
    list2.add(new UITestObject("1", "2", "3", "4"));
    list2.add(new UITestObject("W", "X", "Y", "Z"));
    list2.add(new UITestObject("a", "b", "c", "d"));
    list2.add(new UITestObject("a", "s", "d", "f"));

    list3.add(new UITestObject("A", "B", "C", "D"));
    list3.get(0).getSubList().add(new UITestObject("A", "B", "C", "D"));
    list3.get(0).getSubList().add(new UITestObject("1", "2", "3", "4"));
    list3.get(0).getSubList().add(new UITestObject("W", "X", "Y", "Z"));
    list3.add(new UITestObject("1", "2", "3", "4"));
    list3.get(1).getSubList().add(new UITestObject("A", "B", "C", "D"));
    list3.get(1).getSubList().add(new UITestObject("1", "2", "3", "4"));
    list3.add(new UITestObject("W", "X", "Y", "Z"));
    list3.get(2).getSubList().add(new UITestObject("W", "X", "Y", "Z"));

    list4.add(new UITestObject("A", "B", "C", "D"));
    list4.get(0).getSubList().add(new UITestObject("1", "B", "C", "D", new UITestObject("1", "1", "1", "1")));
    list4.get(0).getSubList().add(new UITestObject("2", "2", "3", "4", new UITestObject("1", "1", "1", "1")));
    list4.get(0).getSubList().add(new UITestObject("3", "X", "Y", "Z", new UITestObject("1", "1", "1", "1")));
    list4.add(new UITestObject("1", "2", "3", "4"));
    list4.get(1).getSubList()
            .add(new UITestObject("4", "b", "C", "D", new UITestObject("$50.00", "1", "1", "1")));
    /*list4.get(1).getSubList().add(new UITestObject("5", "s", "D", "F", new UITestObject("1","1","1","1")));*/

    //triple nesting
    list5.add(new UITestObject("a", "a", "a", "a"));
    list5.get(0).getSubList().add(new UITestObject("A", "B", "C", "D"));
    list5.get(0).getSubList().get(0).getSubList().add(new UITestObject("a3", "3", "3", "3"));
    list5.get(0).getSubList().get(0).getSubList().add(new UITestObject("a3", "3", "3", "3"));
    list5.get(0).getSubList().add(new UITestObject("1", "2", "3", "4"));
    list5.get(0).getSubList().get(1).getSubList().add(new UITestObject("b3", "3", "3", "3"));
    list5.get(0).getSubList().get(1).getSubList().add(new UITestObject("b3", "3", "3", "3"));
    list5.get(0).getSubList().get(1).getSubList().add(new UITestObject("b3", "3", "3", "3"));
    list5.add(new UITestObject("b", "b", "b", "b"));
    list5.get(1).getSubList().add(new UITestObject("a", "b", "C", "D"));
    list5.get(1).getSubList().get(0).getSubList().add(new UITestObject("a23", "3", "3", "3"));
    list5.get(1).getSubList().get(0).getSubList().add(new UITestObject("a23", "3", "3", "3"));
    list5.get(1).getSubList().add(new UITestObject("a", "s", "D", "F"));
    list5.get(1).getSubList().get(1).getSubList().add(new UITestObject("b23", "3", "3", "3"));
    list5.get(1).getSubList().get(1).getSubList().add(new UITestObject("b23", "3", "3", "3"));

    list7 = new ArrayList(list1);
    list8 = new ArrayList(list3);
    list9 = new ArrayList(list1);
    list10 = new ArrayList(list2);
    list11 = new ArrayList(list3);
    list12 = new ArrayList(list1);
    list13 = new ArrayList(list2);
    list14 = new ArrayList(list3);
    list15 = new ArrayList(list1);
    list16 = new ArrayList(list2);
    list17 = new ArrayList(list4);

    groupedList1.add(new UITestObject("A", "100", "200", "300"));
    groupedList1.add(new UITestObject("A", "101", "200", "300"));
    groupedList1.add(new UITestObject("A", "102", "200", "300"));
    groupedList1.add(new UITestObject("A", "103", "200", "300"));
    groupedList1.add(new UITestObject("A", "104", "200", "300"));

    groupedList1.add(new UITestObject("B", "100", "200", "300"));
    groupedList1.add(new UITestObject("B", "101", "200", "300"));
    groupedList1.add(new UITestObject("B", "102", "200", "300"));

    groupedList1.add(new UITestObject("C", "100", "200", "300"));
    groupedList1.add(new UITestObject("C", "101", "200", "300"));
    groupedList1.add(new UITestObject("C", "102", "200", "300"));
    groupedList1.add(new UITestObject("C", "103", "200", "300"));

    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));
    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));
    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));
    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));
    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));
    groupedList1.add(new UITestObject("D", "100", "200", "300"));
    groupedList1.add(new UITestObject("D", "101", "200", "300"));
    groupedList1.add(new UITestObject("D", "102", "200", "300"));
    groupedList1.add(new UITestObject("D", "103", "200", "300"));

    groupedList2.addAll(groupedList1);
    groupedList3.addAll(groupedList1);

    doubleGroupedList.add(new UITestObject("Fall", "2001", "AAA123", "2"));
    doubleGroupedList.add(new UITestObject("Fall", "2001", "BBB123", "3"));
    doubleGroupedList.add(new UITestObject("Fall", "2001", "CCC123", "4"));
    doubleGroupedList.add(new UITestObject("Fall", "2001", "DDD123", "3"));

    doubleGroupedList.add(new UITestObject("Fall", "2002", "AAA123", "3"));
    doubleGroupedList.add(new UITestObject("Fall", "2002", "BBB123", "2"));
    doubleGroupedList.add(new UITestObject("Fall", "2002", "CCC123", "3"));

    doubleGroupedList.add(new UITestObject("Fall", "2003", "AAA123", "3"));
    doubleGroupedList.add(new UITestObject("Fall", "2003", "CCC123", "3"));

    doubleGroupedList.add(new UITestObject("Spring", "2001", "AAA123", "3"));
    doubleGroupedList.add(new UITestObject("Spring", "2001", "BBB123", "3"));
    doubleGroupedList.add(new UITestObject("Spring", "2001", "CCC123", "3"));

    doubleGroupedList.add(new UITestObject("Spring", "2002", "AAA123", "4"));
    doubleGroupedList.add(new UITestObject("Spring", "2002", "BBB123", "4"));
    doubleGroupedList.add(new UITestObject("Spring", "2002", "CCC123", "2"));

    doubleGroupedList.add(new UITestObject("Spring", "2003", "AAA123", "4"));
    doubleGroupedList.add(new UITestObject("Spring", "2003", "BBB123", "3"));
    doubleGroupedList.add(new UITestObject("Spring", "2003", "CCC123", "3"));
    doubleGroupedList.add(new UITestObject("Spring", "2003", "DDD123", "2"));

    for (int i = 0; i < 22; i++) {
        UITestObject newObj = new UITestObject(RandomStringUtils.randomAlphanumeric(6),
                RandomStringUtils.randomAlphanumeric(6), RandomStringUtils.randomAlphanumeric(6),
                RandomStringUtils.randomNumeric(1));

        if (i % 2 == 0) {
            newObj.setBfield(true);
        }

        list6.add(newObj);
    }

    { // scope for name hiding purposes
        Node<String, String> item1 = new Node<String, String>("Item 1", "Item 1");
        item1.addChild(new Node<String, String>("SubItem A", "SubItem A"));
        item1.addChild(new Node<String, String>("SubItem B", "SubItem B"));

        Node<String, String> item2 = new Node<String, String>("Item 2", "Item 2");
        item2.addChild(new Node<String, String>("SubItem A", "SubItem A"));
        Node<String, String> sub2B = new Node<String, String>("SubItem B", "SubItem B");
        sub2B.addChild(new Node<String, String>("Item B-1", "Item B-1"));
        sub2B.addChild(new Node<String, String>("Item B-2", "Item B-2"));
        sub2B.addChild(new Node<String, String>("Item B-3", "Item B-3"));
        item2.addChild(sub2B);
        item2.addChild(new Node<String, String>("SubItem C", "SubItem C"));

        Node<String, String> item3 = new Node<String, String>("Item 3", "Item 3");
        item3.addChild(new Node<String, String>("SubItem A", "SubItem A"));
        item3.addChild(new Node<String, String>("SubItem B", "SubItem B"));
        item3.addChild(new Node<String, String>("SubItem C", "SubItem C"));
        item3.addChild(new Node<String, String>("SubItem D", "SubItem D"));

        Node<String, String> root = new Node<String, String>("Root", "Root");
        root.addChild(item1);
        root.addChild(item2);
        root.addChild(item3);

        tree1.setRootElement(root);
    }

    { // scope for name hiding purposes
        Node<UITestObject, String> item1 = new Node<UITestObject, String>(
                new UITestObject("1-A", "1-B", "1-C", "1-D"), "Item 1");
        item1.addChild(new Node<UITestObject, String>(new UITestObject("1SA-A", "1SA-B", "1SA-C", "1SA-D"),
                "SubItem A"));
        item1.addChild(new Node<UITestObject, String>(new UITestObject("1SB-A", "1SB-B", "1SB-C", "1SB-D"),
                "SubItem B"));

        Node<UITestObject, String> item2 = new Node<UITestObject, String>(
                new UITestObject("2-A", "2-B", "2-C", "2-D"), "Item 2");
        item2.addChild(
                new Node<UITestObject, String>(new UITestObject("SA-a", "SA-b", "SA-c", "SA-d"), "SubItem A"));
        Node<UITestObject, String> sub2B = new Node<UITestObject, String>(
                new UITestObject("SB-a", "SB-b", "SB-c", "SB-d"), "SubItem B");
        sub2B.addChild(new Node<UITestObject, String>(new UITestObject("AA", "BB", "CC", "DD"), "Item B-1"));
        sub2B.addChild(new Node<UITestObject, String>(new UITestObject("Aa", "Bb", "Cc", "Dd"), "Item B-2"));
        sub2B.addChild(new Node<UITestObject, String>(new UITestObject("aA", "bB", "cC", "dD"), "Item B-3"));
        item2.addChild(sub2B);
        item2.addChild(
                new Node<UITestObject, String>(new UITestObject("SC-a", "SC-b", "SC-c", "SC-d"), "SubItem C"));

        Node<UITestObject, String> item3 = new Node<UITestObject, String>(
                new UITestObject("3-A", "3-B", "3-C", "3-D"), "Item 3");
        item3.addChild(new Node<UITestObject, String>(new UITestObject("A", "B", "C", "D"), "SubItem A"));
        item3.addChild(new Node<UITestObject, String>(new UITestObject("1", "2", "3", "4"), "SubItem B"));
        item3.addChild(new Node<UITestObject, String>(new UITestObject("w", "x", "y", "z"), "SubItem C"));
        item3.addChild(new Node<UITestObject, String>(new UITestObject("!", "@", "#", "$"), "SubItem D"));

        Node<UITestObject, String> root = new Node<UITestObject, String>(
                new UITestObject("foo", "bar", "baz", "roo"), "Root");
        root.addChild(item1);
        root.addChild(item2);
        root.addChild(item3);

        tree2.setRootElement(root);
    }

    remoteFieldValuesMap = new HashMap<String, Object>();
    remoteFieldValuesMap.put("remoteField1", "Apple");
    remoteFieldValuesMap.put("remoteField2", "Banana");
    remoteFieldValuesMap.put("remoteField3", true);
    remoteFieldValuesMap.put("remoteField4", "Fruit");

    remoteFieldValuesMap2 = new HashMap<String, Object>();
    remoteFieldValuesMap2.put("remoteField1", "Apple");
    remoteFieldValuesMap2.put("remoteField2", "Banana");
    remoteFieldValuesMap2.put("remoteField3", true);
    remoteFieldValuesMap2.put("remoteField4", "Fruit");

    LocalDateTime dayEventStart = LocalDateTime.parse("2010-10-01");
    dayEvents.add(new DayEvent("fifth", dayEventStart.plusDays(4).toDate(), "10:00", "AM", false));
    dayEvents.add(new DayEvent("fourth", dayEventStart.plusDays(3).toDate(), "04:00", "PM", false));
    dayEvents.add(new DayEvent("first", dayEventStart.toDate(), "10:00", "AM", false));
    dayEvents.add(new DayEvent("second", dayEventStart.plusDays(1).toDate(), "12:00", "PM", false));
    dayEvents.add(new DayEvent("third", dayEventStart.plusDays(2).toDate(), "02:00", "PM", false));

    field88 = "Fruits";
    field91 = "Read only value";
    field92 = "Value 92";

    field131 = new Integer(0);

    DateFormat dateFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
    dateList = new ArrayList<Date>();
    try {
        dateList.add(dateFormat.parse("01/01/1990"));
        dateList.add(dateFormat.parse("10/31/2001"));
        dateList.add(dateFormat.parse("11/05/2005"));
        dateList.add(dateFormat.parse("02/13/2011"));
    } catch (Exception e) {

    }

    emptyList.clear();
}

From source file:energy.usef.agr.model.SynchronisationConnection.java

License:Apache License

public void setLastSynchronisationTime(LocalDateTime lastSynchronisationTime) {
    if (lastSynchronisationTime == null) {
        this.lastSynchronisationTime = null;
    } else {/* w  ww .ja  v  a 2s. c o m*/
        this.lastSynchronisationTime = lastSynchronisationTime.toDateTime().toDate();
    }
}