Example usage for org.apache.commons.lang3.time DateUtils toCalendar

List of usage examples for org.apache.commons.lang3.time DateUtils toCalendar

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils toCalendar.

Prototype

public static Calendar toCalendar(final Date date) 

Source Link

Document

Converts a Date into a Calendar .

Usage

From source file:ca.uhn.fhir.rest.param.ParameterUtil.java

public static Object fromInstant(Class<?> theType, InstantDt theArgument) {
    if (theType.equals(InstantDt.class)) {
        if (theArgument == null) {
            return new InstantDt();
        }//from w  w  w .  ja v a 2 s  .  c om
        return theArgument;
    }
    if (theType.equals(Date.class)) {
        if (theArgument == null) {
            return null;
        }
        return theArgument.getValue();
    }
    if (theType.equals(Calendar.class)) {
        if (theArgument == null) {
            return null;
        }
        return DateUtils.toCalendar(theArgument.getValue());
    }
    throw new IllegalArgumentException("Invalid instant type:" + theType);
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static int getCalendarDayOfWeek(Date date) {
    return DateUtils.toCalendar(date).get(Calendar.DAY_OF_WEEK);
}

From source file:jp.dip.komusubi.botter.gae.module.FlightStatusTwitter.java

@Override
public boolean available(Map<String, List<String>> param) {
    List<String> values = param.get("route");
    // 15??/*w  w w .  ja v a 2 s. c om*/
    Calendar limitTime = DateUtils.toCalendar(dateResolver.resolve());
    limitTime.add(Calendar.MINUTE, -15);

    // ??15??????????
    flights = new ArrayList<FlightStatus>();
    // ??
    if (values == null || values.size() == 0) {
        flights.addAll(flightStatusDao.findByBeforeDeparture(limitTime.getTime()));
        flights.addAll(flightStatusDao.findByBeforeArrival(limitTime.getTime()));
    } else {
        for (String value : values) {
            // FIXME validate query parameter
            String[] airports = normalize(value);
            Route route = routeDao.readByAirportCode(airports[0], airports[1]);
            if (route == null) {
                logger.warn("not found Route, " + "query parameter is wrong:{} and {}", airports[0],
                        airports[1]);
                continue;
            }
            flights.addAll(flightStatusDao.findByBeforeDeparture(limitTime.getTime(), value));
            flights.addAll(flightStatusDao.findByBeforeArrival(limitTime.getTime(), value));
        }
    }
    logger.info("delay flight count is {}", flights.size());
    return flights.size() > 0;
}

From source file:com.norconex.commons.lang.time.YearMonthDay.java

/**
 * Constructs a YearMonthDay from a {@link Date}.
 * @param date a date
 */
public YearMonthDay(Date date) {
    this(DateUtils.toCalendar(date));
}

From source file:io.wcm.testing.mock.sling.resource.JcrResourceResolverTest.java

@Before
public final void setUp() throws RepositoryException {
    this.resourceResolver = newResourceResolver();
    this.session = this.resourceResolver.adaptTo(Session.class);

    // prepare some test data using JCR API
    Node rootNode = getTestRootNode();
    Node node1 = rootNode.addNode("node1", JcrConstants.NT_UNSTRUCTURED);

    node1.setProperty("stringProp", STRING_VALUE);
    node1.setProperty("stringArrayProp", STRING_ARRAY_VALUE);
    node1.setProperty("integerProp", INTEGER_VALUE);
    node1.setProperty("doubleProp", DOUBLE_VALUE);
    node1.setProperty("booleanProp", BOOLEAN_VALUE);
    node1.setProperty("dateProp", DateUtils.toCalendar(DATE_VALUE));
    node1.setProperty("calendarProp", CALENDAR_VALUE);
    node1.setProperty("binaryProp",
            this.session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY_VALUE)));

    node1.addNode("node11", JcrConstants.NT_UNSTRUCTURED);
    node1.addNode("node12", JcrConstants.NT_UNSTRUCTURED);

    this.session.save();
}

From source file:jp.dip.komusubi.botter.gae.module.jal5971.FlightStatusScraper.java

protected String buildUrl(String baseUrl) {
    String queryFragments = null;
    Calendar current = DateUtils.toCalendar(dateResolver.resolve());
    Calendar requested = DateUtils.toCalendar(this.date);
    Calendar tomorrow = (Calendar) current.clone();
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    Calendar yesterday = (Calendar) current.clone();
    yesterday.add(Calendar.DAY_OF_MONTH, -1);

    if (DateUtils.truncatedEquals(requested, yesterday, Calendar.DAY_OF_MONTH)) {
        queryFragments = "&DATEFLG=1"; // ?
    } else if (DateUtils.truncatedEquals(requested, tomorrow, Calendar.DAY_OF_MONTH)) {
        queryFragments = "&DATEFLG=2"; // 
    } else if (DateUtils.truncatedEquals(requested, current, Calendar.DAY_OF_MONTH)) {
        queryFragments = "";
    }//  w w w.j  av a  2s.  c om
    if (queryFragments == null)
        throw new IllegalStateException("requested date: " + DateFormatUtils.format(requested, "yyyy/MM/dd")
                + " was over rage, current date is " + DateFormatUtils.format(current, "yyyy/MM/dd"));

    StringBuilder builder = new StringBuilder(baseUrl);
    builder.append("?DPORT=").append(route.getDeparture().getCode()).append("&APORT=")
            .append(route.getArrival().getCode()).append(queryFragments);
    return builder.toString();
}

From source file:com.matrimony.database.UserDAO.java

public static int getAgeByBirthday(Date birthday) {
    Calendar now = DateUtils.toCalendar(new Date(System.currentTimeMillis()));
    Calendar before = DateUtils.toCalendar(birthday);
    return now.get(Calendar.YEAR) - before.get(Calendar.YEAR);
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.ValueConverterTest.java

@Test
public void testCalendar() {
    assertTrue(StringUtils.startsWith(underTest.toString("prop", DateUtils.toCalendar(sampleDate)),
            "{Date}2010-09-05T15:10:20"));
}

From source file:gov.nih.nci.firebird.selenium2.pages.components.tags.DateSelectTagHelper.java

public void setDate(Date date) {
    if (date == null) {
        clearDate();/*from w  w w  .j a v a 2s.  co m*/
    } else {
        tag.selectMonth(DateUtils.toCalendar(date).get(Calendar.MONTH) + 1);
        tag.selectYear(DateUtils.toCalendar(date).get(Calendar.YEAR));
    }
}

From source file:cn.mypandora.util.MyDateUtils.java

/**
 * ???X/*from   ww  w  .  j a  v a  2  s .  c  o  m*/
 *
 * @param specifiedDate ,?YYYY-MM-DD
 * @param offset        ??
 * @return
 * @throws ParseException
 */
public static String getSpecifiedOffsetDate(String specifiedDate, int offset) throws ParseException {
    Date date = DateUtils.parseDate(specifiedDate, DATE_FORMAT);
    Calendar cal = DateUtils.toCalendar(date);
    cal.add(Calendar.DAY_OF_MONTH, offset);
    String returnDate = DateFormatUtils.format(cal, DATE_FORMAT);
    return returnDate;
}