Search in sources :

Example 81 with GregorianCalendar

use of java.util.GregorianCalendar in project rest.li by linkedin.

the class TestCustomTypesClient method testCalendarRefQueryParam.

@Test
public void testCalendarRefQueryParam() throws RemoteInvocationException {
    FindRequest<Greeting> findRequest = new CustomTypesRequestBuilders().findByCalendar().calendarParam(new GregorianCalendar()).build();
    Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    Assert.assertEquals(response.getEntity().getElements().size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypesRequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypesRequestBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) GregorianCalendar(java.util.GregorianCalendar) Test(org.testng.annotations.Test)

Example 82 with GregorianCalendar

use of java.util.GregorianCalendar in project jforum2 by rafaelsteil.

the class LuceneStatsAction method buildDateFromRequest.

private Date buildDateFromRequest(String prefix) {
    String day = this.request.getParameter(prefix + "Day");
    String month = this.request.getParameter(prefix + "Month");
    String year = this.request.getParameter(prefix + "Year");
    String hour = this.request.getParameter(prefix + "Hour");
    String minutes = this.request.getParameter(prefix + "Minutes");
    Date date = null;
    if (!StringUtils.isEmpty(day) && !StringUtils.isEmpty(month) && !StringUtils.isEmpty(year) && !StringUtils.isEmpty(hour) && !StringUtils.isEmpty(minutes)) {
        date = new GregorianCalendar(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(year), Integer.parseInt(hour), Integer.parseInt(minutes), 0).getTime();
    }
    return date;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 83 with GregorianCalendar

use of java.util.GregorianCalendar in project benCoding.AlarmManager by benbahrenburg.

the class AlarmManagerProxy method getFullCalendar.

private Calendar getFullCalendar(KrollDict args) {
    Calendar defaultDay = Calendar.getInstance();
    int day = args.optInt("day", defaultDay.get(Calendar.DAY_OF_MONTH));
    int month = args.optInt("month", defaultDay.get(Calendar.MONTH));
    int year = args.optInt("year", defaultDay.get(Calendar.YEAR));
    int hour = args.optInt("hour", defaultDay.get(Calendar.HOUR_OF_DAY));
    int minute = args.optInt("minute", defaultDay.get(Calendar.MINUTE));
    int second = args.optInt("second", defaultDay.get(Calendar.SECOND));
    Calendar cal = new GregorianCalendar(year, month, day);
    cal.add(Calendar.HOUR_OF_DAY, hour);
    cal.add(Calendar.MINUTE, minute);
    cal.add(Calendar.SECOND, second);
    return cal;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 84 with GregorianCalendar

use of java.util.GregorianCalendar in project ExoPlayer by google.

the class Util method parseXsDateTime.

/**
   * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since
   * the epoch.
   *
   * @param value The attribute value to decode.
   * @return The parsed timestamp in milliseconds since the epoch.
   * @throws ParserException if an error occurs parsing the dateTime attribute value.
   */
public static long parseXsDateTime(String value) throws ParserException {
    Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
    if (!matcher.matches()) {
        throw new ParserException("Invalid date/time format: " + value);
    }
    int timezoneShift;
    if (matcher.group(9) == null) {
        // No time zone specified.
        timezoneShift = 0;
    } else if (matcher.group(9).equalsIgnoreCase("Z")) {
        timezoneShift = 0;
    } else {
        timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13))));
        if (matcher.group(11).equals("-")) {
            timezoneShift *= -1;
        }
    }
    Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    dateTime.clear();
    // Note: The month value is 0-based, hence the -1 on group(2)
    dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)), Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6)));
    if (!TextUtils.isEmpty(matcher.group(8))) {
        final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
        // we care only for milliseconds, so movePointRight(3)
        dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
    }
    long time = dateTime.getTimeInMillis();
    if (timezoneShift != 0) {
        time -= timezoneShift * 60000;
    }
    return time;
}
Also used : ParserException(com.google.android.exoplayer2.ParserException) Matcher(java.util.regex.Matcher) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Point(android.graphics.Point) BigDecimal(java.math.BigDecimal)

Example 85 with GregorianCalendar

use of java.util.GregorianCalendar in project binnavi by google.

the class DateHelpers method getDate.

/**
   * Extracts the date from a user defined date String.
   * 
   * @param dateString The date string to extract the date from.
   * @param format The format of the date string (e.g: MM-DD-YYYY)
   * 
   * @return The current date.
   */
public static Date getDate(final String dateString, final String format) {
    Preconditions.checkArgument(dateString.length() == format.length(), "Date string format exception. Format string must have the same length as the date string.");
    String day = "";
    String month = "";
    String year = "";
    for (int i = 0; i < format.length(); ++i) {
        final char chr = format.charAt(i);
        if (chr == 'D') {
            day += dateString.charAt(i);
        } else if (chr == 'M') {
            month += dateString.charAt(i);
        } else if (chr == 'Y') {
            year += dateString.charAt(i);
        }
    }
    Preconditions.checkArgument(day.length() == 2, "Date string format exception. Date string's day field must have two chars.");
    Preconditions.checkArgument(month.length() == 2, "Date string format exception. Date string's month field must have two chars.");
    Preconditions.checkArgument(year.length() == 4, "Date string format exception. Date string's years field must have four chars.");
    final int iday = Integer.parseInt(day);
    final int imonth = Integer.parseInt(month) - 1;
    final int iyear = Integer.parseInt(year);
    final GregorianCalendar calendar = new GregorianCalendar(iyear, imonth, iday);
    return calendar.getTime();
}
Also used : GregorianCalendar(java.util.GregorianCalendar)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1278 Calendar (java.util.Calendar)603 Date (java.util.Date)377 Test (org.junit.Test)247 SimpleDateFormat (java.text.SimpleDateFormat)104 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)48 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)39 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)28 SQLException (java.sql.SQLException)20 DateFormat (java.text.DateFormat)18 IOException (java.io.IOException)16 Map (java.util.Map)16