Example usage for org.joda.time DateTime getHourOfDay

List of usage examples for org.joda.time DateTime getHourOfDay

Introduction

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

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:com.aionemu.gameserver.services.instance.PvPArenaService.java

License:Open Source License

private static boolean isGloryArenaAvailable() {
    DateTime now = DateTime.now();
    int hour = now.getHourOfDay();
    int day = now.getDayOfWeek();
    return (day == 6 || day == 7) && hour >= 20 && hour < 22;
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.ConfigurationToOslpSetConfigurationRequestConverter.java

License:Open Source License

private String convertSummerTimeWinterTimeDetails(final DateTime dateTime) {
    LOGGER.info("dateTime: {}", dateTime);

    final StringBuilder timeDetails = new StringBuilder();
    timeDetails.append(String.format("%02d", dateTime.getMonthOfYear()));
    timeDetails.append(dateTime.getDayOfWeek() - 1);
    timeDetails.append(String.format("%02d", dateTime.getHourOfDay()));
    timeDetails.append(String.format("%02d", dateTime.getMinuteOfHour()));
    final String formattedTimeDetails = timeDetails.toString();

    LOGGER.info("formattedTimeDetails: {}", formattedTimeDetails);

    return formattedTimeDetails;
}

From source file:com.barchart.feed.ddf.util.HelperDDF.java

License:BSD License

/**
 * from millisUTC into ddf "20100616124807".
 * //from ww w  .  j a  va  2 s. c  om
 * @param millisUTC
 *            the millis utc
 * @param zone
 *            the zone
 * @return the long
 */
public static final long timeEncode(final long millisUTC, final DateTimeZone zone) {

    final DateTime dateTime = new DateTime(millisUTC, zone);
    long value = 0;
    final int year = dateTime.getYearOfEra();
    value += year;
    value *= 100;
    final int month = dateTime.getMonthOfYear();
    value += month;
    value *= 100;
    final int day = dateTime.getDayOfMonth();
    value += day;
    value *= 100;
    final int hour = dateTime.getHourOfDay();
    value += hour;
    value *= 100;
    final int minute = dateTime.getMinuteOfHour();
    value += minute;
    value *= 100;
    final int second = dateTime.getSecondOfMinute();
    value += second;
    return value;
}

From source file:com.barchart.feed.test.replay.DDFLogDeframer.java

License:BSD License

static final void encodeTimeStamp(final String timestamp, final ByteBuffer buffer) {

    DateTime dateTime = timeParser.parseDateTime(timestamp);

    // base fields
    buffer.put(DDF_CENTURY); // century
    buffer.put(encodeTimeStampByte(dateTime.getYearOfCentury())); // year
    buffer.put(encodeTimeStampByte(dateTime.getMonthOfYear())); // month
    buffer.put(encodeTimeStampByte(dateTime.getDayOfMonth())); // day
    buffer.put(encodeTimeStampByte(dateTime.getHourOfDay())); // hours
    buffer.put(encodeTimeStampByte(dateTime.getMinuteOfHour())); // minutes
    buffer.put(encodeTimeStampByte(dateTime.getSecondOfMinute())); // seconds

    // milliseconds
    final int millisOfSecond = dateTime.getMillisOfSecond();
    buffer.put((byte) (millisOfSecond & 0xFF)); // low byte
    buffer.put((byte) ((millisOfSecond >>> 8) & 0xFF)); // high byte

}

From source file:com.cfelde.aws.ddb.management.TableThroughput.java

License:Open Source License

public boolean isDownscaleAllowed() {
    // We allow 4 downscales within 24 hours:

    // Between 00:00 and 06:00 - 3 left after
    // Between 06:00 and 12:00 - 2 left after
    // Between 12:00 and 18:00 - 1 left after
    // Between 18:00 and 00:00 - 0 left after

    // First, based on current UTC time, find the number of
    // downscales we at most can use.
    DateTime dtNow = new DateTime(DateTimeZone.UTC);

    int hourNow = dtNow.getHourOfDay();
    long maxDownscales;
    if (hourNow >= 18)
        maxDownscales = 4;//from  ww w . ja  v  a 2s . c  o  m
    else if (hourNow >= 12)
        maxDownscales = 3;
    else if (hourNow >= 6)
        maxDownscales = 2;
    else
        maxDownscales = 1;

    long usedDownscaled = downscaleCounter.get();

    return usedDownscaled < maxDownscales;
}

From source file:com.cfelde.cron4joda.SchedulingPattern.java

License:Open Source License

/**
 * This methods returns true if the given timestamp (expressed as a UNIX-era
 * millis value) matches the pattern, according to the given time zone.
 *
 * @param timezone A time zone./* www  .  ja v a2 s .  co m*/
 * @param millis The timestamp, as a UNIX-era millis value.
 * @return true if the given timestamp matches the pattern.
 */
public boolean match(DateTime dt) {
    int minute = dt.getMinuteOfHour();
    int hour = dt.getHourOfDay();
    int dayOfMonth = dt.getDayOfMonth();
    int month = dt.getMonthOfYear(); //gc.get(Calendar.MONTH) + 1;
    int dayOfWeek = dt.getDayOfWeek(); //gc.get(Calendar.DAY_OF_WEEK) - 1;

    for (int i = 0; i < matcherSize; i++) {
        ValueMatcher minuteMatcher = (ValueMatcher) minuteMatchers.get(i);
        ValueMatcher hourMatcher = (ValueMatcher) hourMatchers.get(i);
        ValueMatcher dayOfMonthMatcher = (ValueMatcher) dayOfMonthMatchers.get(i);
        ValueMatcher monthMatcher = (ValueMatcher) monthMatchers.get(i);
        ValueMatcher dayOfWeekMatcher = (ValueMatcher) dayOfWeekMatchers.get(i);

        boolean eval = minuteMatcher.match(minute) && hourMatcher.match(hour)
                && ((dayOfMonthMatcher instanceof DayOfMonthValueMatcher)
                        ? ((DayOfMonthValueMatcher) dayOfMonthMatcher).match(dayOfMonth, month,
                                dt.year().getField().isLeap(dt.getMillis())) /*gc.isLeapYear(year))*/
                        : dayOfMonthMatcher.match(dayOfMonth))
                && monthMatcher.match(month) && dayOfWeekMatcher.match(dayOfWeek);

        if (eval) {
            return true;
        }
    }

    return false;
}

From source file:com.clevercloud.bianca.lib.date.DateModule.java

License:Open Source License

/**
 * Returns the parsed date./* w w w  . j av  a 2  s . c o m*/
 */
public Value strptime(Env env, String date, String format) {
    ArrayValueImpl array = new ArrayValueImpl();
    DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder();

    int length = format.length();

    for (int i = 0; i < length; i++) {
        char ch = format.charAt(i);
        if (ch != '%') {
            fb.appendLiteral(ch);
            continue;
        }

        switch (format.charAt(++i)) {
        case 'a':
            fb.appendDayOfWeekShortText();
            break;

        case 'A':
            fb.appendDayOfWeekText();
            break;

        case 'h':
        case 'b':
            fb.appendMonthOfYearShortText();
            ;
            break;

        case 'B':
            fb.appendMonthOfYearText();
            break;

        // TODO: case 'c'

        case 'C':
            fb.appendCenturyOfEra(2, 2);
            break;

        case 'd':
            fb.appendDayOfMonth(2);
            break;

        case 'D':
            fb.appendMonthOfYear(2);
            fb.appendLiteral('/');
            fb.appendDayOfMonth(2);
            fb.appendLiteral('/');
            fb.appendYear(2, 2);
            break;

        // TODO: case 'e'

        case 'F':
            fb.appendYear(4, 4);
            fb.appendLiteral('-');
            fb.appendMonthOfYear(2);
            fb.appendLiteral('-');
            fb.appendDayOfMonth(2);
            break;

        // TODO: case 'g'
        // TODO: case 'G'

        case 'H':
            fb.appendHourOfDay(2);
            break;

        case 'I':
            fb.appendHourOfHalfday(2);
            break;

        case 'j':
            fb.appendDayOfYear(3);
            break;

        // TODO: case 'l'

        case 'm':
            fb.appendMonthOfYear(2);
            break;

        case 'M':
            fb.appendMinuteOfHour(2);
            break;

        case 'n':
            fb.appendLiteral("\n");
            break;

        case 'p':
        case 'P':
            fb.appendHalfdayOfDayText();
            break;

        case 'r':
            fb.appendHourOfHalfday(2);
            fb.appendLiteral(':');
            fb.appendMinuteOfHour(2);
            fb.appendLiteral(':');
            fb.appendSecondOfMinute(2);
            fb.appendLiteral(' ');
            fb.appendHalfdayOfDayText();
            break;

        case 'R':
            fb.appendHourOfDay(2);
            fb.appendLiteral(':');
            fb.appendMinuteOfHour(2);
            break;

        // TODO: case 's'

        case 'S':
            fb.appendSecondOfMinute(2);
            break;

        case 't':
            fb.appendLiteral("\t");
            break;

        case 'T':
            fb.appendHourOfDay(2);
            fb.appendLiteral(':');
            fb.appendMinuteOfHour(2);
            fb.appendLiteral(':');
            fb.appendSecondOfMinute(2);
            break;

        // TODO: case 'u'
        // TODO: case 'U'
        // TODO: case 'V'
        // TODO: case 'w'
        // TODO: case 'W'
        // TODO: case 'x'
        // TODO: case 'X'

        case 'y':
            fb.appendYear(2, 2);
            break;

        case 'Y':
            fb.appendYear(4, 4);
            break;

        case 'z':
            fb.appendTimeZoneOffset(null, true, 2, 2);
            break;

        case 'Z':
            fb.appendTimeZoneName();
            break;

        case '%':
            fb.appendLiteral('%');
            break;

        default:
            fb.appendLiteral(ch);
        }
    }

    DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed();

    org.joda.time.DateTime dt = new org.joda.time.DateTime();

    String unparsed = "";

    try {
        dt = dtf.parseDateTime(date);
    } catch (IllegalArgumentException e) {
        String delims = "[\"]+";

        String[] splits = e.getMessage().split(delims);

        unparsed = unparsed.concat(splits[3]);
    }

    // According to manual strptime(3)
    if (dt.getCenturyOfEra() == 0) {
        if (dt.getYear() > 68) {
            dt = dt.withCenturyOfEra(19);
        } else {
            dt = dt.withCenturyOfEra(20);
        }
    }

    array.put("tm_sec", dt.getSecondOfMinute());
    array.put("tm_min", dt.getMinuteOfHour());
    array.put("tm_hour", dt.getHourOfDay());
    array.put("tm_mday", dt.getDayOfMonth());
    array.put("tm_mon", dt.getMonthOfYear() - 1);
    array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900
    array.put("tm_wday", dt.getDayOfWeek() % 7);
    array.put("tm_yday", dt.getDayOfYear() - 1);
    array.put("unparsed", unparsed);

    return array;
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest hour. The time zone of the returned DateTime
 * instance will be the same as the argument. Similar to a floor() function
 * on a float.<br>//w w w  . ja  v  a  2  s .com
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:00:00.000 -8:00"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest hour.
 */
public static DateTime floorToHour(DateTime value) {
    if (value == null) {
        return null;
    }
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), 0,
            0, 0, value.getZone());
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest specified period in minutes. For example, if
 * a period of 5 minutes is requested, a time of "2009-06-24 13:24:51.476 -8:00"
 * would return a datetime of "2009-06-24 13:20:00.000 -8:00". The time zone of the
 * returned DateTime instance will be the same as the argument. Similar to a
 * floor() function on a float.<br>
 * NOTE: While any period in minutes between 1 and 59 can be passed into this
 * method, its only useful if the value can be evenly divided into 60 to make
 * it as useful as possible.<br>//from  ww  w.jav a2s .  co  m
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>5: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:35:00.000 -8:00"
 *      <li>10: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00"
 *      <li>15: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00"
 *      <li>20: "2009-06-24 13:39:51.476 UTC" -> "2009-06-24 13:20:00.000 UTC"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest period in minutes.
 */
public static DateTime floorToMinutePeriod(DateTime value, int periodInMinutes) {
    if (value == null) {
        return null;
    }
    if (periodInMinutes <= 0 || periodInMinutes > 59) {
        throw new IllegalArgumentException("period in minutes must be > 0 and <= 59");
    }
    int min = value.getMinuteOfHour();
    min = (min / periodInMinutes) * periodInMinutes;
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(),
            min, 0, 0, value.getZone());
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest minute. The time zone of the returned DateTime
 * instance will be the same as the argument. Similar to a floor() function
 * on a float.<br>// www  .  ja v a  2  s  . co m
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:00.000 -8:00"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest minute.
 */
public static DateTime floorToMinute(DateTime value) {
    if (value == null) {
        return null;
    }
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(),
            value.getMinuteOfHour(), 0, 0, value.getZone());
}