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.google.sampling.experiential.model.SignalSchedule.java

License:Open Source License

public String getHourOffsetAsTimeString(Long time) {
    DateTime endHour = new DateMidnight().toDateTime().plus(time);
    String endHourString = endHour.getHourOfDay() + ":" + pad(endHour.getMinuteOfHour());
    return endHourString;
}

From source file:com.google.sampling.experiential.model.SignalSchedule.java

License:Open Source License

public String getHourOffsetAsTimeString(SignalTime time) {
    DateTime endHour = new DateMidnight().toDateTime().plus(time.getFixedTimeMillisFromMidnight());
    String endHourString = endHour.getHourOfDay() + ":" + pad(endHour.getMinuteOfHour());
    return endHourString;
}

From source file:com.gst.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java

License:Apache License

/**
 * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime
 * /*from  w w w  .  j  a  va2s .  c om*/
 * @param recurrencePattern
 * @param startDateTime
 * @return DateTime object
 */
private DateTime createNextRecurringDateTime(final String recurrencePattern, final DateTime startDateTime) {
    DateTime nextRecurringDateTime = null;

    // the recurrence pattern/rule cannot be empty
    if (StringUtils.isNotBlank(recurrencePattern) && startDateTime != null) {
        final LocalDate nextDayLocalDate = startDateTime.plus(1).toLocalDate();
        final LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern,
                startDateTime.toLocalDate(), nextDayLocalDate);
        final String nextDateTimeString = nextRecurringLocalDate + " " + startDateTime.getHourOfDay() + ":"
                + startDateTime.getMinuteOfHour() + ":" + startDateTime.getSecondOfMinute();
        final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATETIME_FORMAT);

        nextRecurringDateTime = DateTime.parse(nextDateTimeString, dateTimeFormatter);
    }

    return nextRecurringDateTime;
}

From source file:com.hangum.tadpold.commons.libs.core.sqls.ParameterUtils.java

License:Open Source License

/**
 * original code is  http://www.gotoquiz.com/web-coding/programming/java-programming/log-sql-statements-with-parameter-values-filled-in-spring-jdbc/
 * //from w w  w  . ja va 2s  . c o m
 * @param statement
 * @param sqlArgs
 * @return
 */
public static String fillParameters(String statement, Object[] sqlArgs) {
    // initialize a StringBuilder with a guesstimated final length
    StringBuilder completedSqlBuilder = new StringBuilder(Math.round(statement.length() * 1.2f));
    int index, // will hold the index of the next ?
            prevIndex = 0; // will hold the index of the previous ? + 1

    // loop through each SQL argument
    for (Object arg : sqlArgs) {
        index = statement.indexOf("?", prevIndex);
        if (index == -1)
            break; // bail out if there's a mismatch in # of args vs. ?'s

        // append the chunk of SQL coming before this ?
        completedSqlBuilder.append(statement.substring(prevIndex, index));
        if (arg == null)
            completedSqlBuilder.append("NULL");
        else if (arg instanceof String) {
            // wrap the String in quotes and escape any quotes within
            completedSqlBuilder.append('\'').append(arg.toString().replace("'", "''")).append('\'');
        } else if (arg instanceof Date) {
            // convert it to a Joda DateTime
            DateTime dateTime = new DateTime((Date) arg);
            // test to see if it's a DATE or a TIMESTAMP
            if (dateTime.getHourOfDay() == LocalTime.MIDNIGHT.getHourOfDay()
                    && dateTime.getMinuteOfHour() == LocalTime.MIDNIGHT.getMinuteOfHour()
                    && dateTime.getSecondOfMinute() == LocalTime.MIDNIGHT.getSecondOfMinute()) {
                completedSqlBuilder.append("DATE '").append(DATE_FORMATTER.print(dateTime)).append('\'');
            } else {
                completedSqlBuilder.append("TIMESTAMP '").append(TIMESTAMP_FORMATTER.print(dateTime))
                        .append('\'');
            }
        } else
            completedSqlBuilder.append(arg.toString());

        prevIndex = index + 1;
    }

    // add the rest of the SQL if any
    if (prevIndex != statement.length())
        completedSqlBuilder.append(statement.substring(prevIndex));

    return completedSqlBuilder.toString();
}

From source file:com.hmsinc.epicenter.webapp.chart.TimeSeriesChart.java

License:Open Source License

/**
 * @param period/*from  www  .  j a  v  a2s .  c  o m*/
 * @param date
 * @return
 */
private static org.jfree.data.time.RegularTimePeriod getEntryPeriod(final TimeSeriesPeriod period,
        final DateTime date) {

    final org.jfree.data.time.RegularTimePeriod ret;

    switch (period) {
    case DAY:
        ret = new Day(date.getDayOfMonth(), date.getMonthOfYear(), date.getYear());
        break;
    case HOUR:
        ret = new Hour(date.getHourOfDay(), date.getDayOfYear(), date.getMonthOfYear(), date.getYear());
        break;
    case MONTH:
        ret = new Month(date.getMonthOfYear(), date.getYear());
        break;
    case YEAR:
        ret = new Year(date.getYear());
        break;
    default:
        throw new UnsupportedOperationException("Unsupported period: " + period);
    }

    return ret;

}

From source file:com.hotwire.test.steps.livechat.LiveChatModelWebApp.java

License:Open Source License

public boolean isChatOperationHours() {
    DateTime currentDateTime = new DateTime();
    if ((currentDateTime.getHourOfDay() >= 5) && (currentDateTime.getHourOfDay() <= 22)) {
        return true;
    }/*  www.  java2 s.  c  o m*/
    return false;
}

From source file:com.jay.pea.mhealthapp2.model.Dose.java

License:Open Source License

public void setTakenTime(DateTime takenTime) {

    this.takenTime = new DateTime().withHourOfDay(takenTime.getHourOfDay())
            .withMinuteOfHour(takenTime.getMinuteOfHour());
    if (takenTime != new DateTime(0))
        this.doseTaken = true;
    else/*from  ww  w.  j  a  v  a  2  s.  co  m*/
        this.doseTaken = false;
}

From source file:com.jive.myco.seyren.core.domain.Subscription.java

License:Apache License

private boolean isCorrectHourOfDay(DateTime time) {
    LocalTime alertTime = new LocalTime(time.getHourOfDay(), time.getMinuteOfHour());
    return alertTime.isAfter(getFromTime()) && alertTime.isBefore(getToTime());
}

From source file:com.kopysoft.chronos.activities.Editors.NewPunchActivity.java

License:Open Source License

@Override
public void onCreate(Bundle savedInstanceState) {
    if (enableLog)
        Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.punch_pair_editor);

    Spinner taskSpinnerIn = (Spinner) findViewById(R.id.taskSpinnerIn);
    Spinner taskSpinnerOut = (Spinner) findViewById(R.id.taskSpinnerOut);
    try {//from ww w  .j  a  va 2s  .c  o m
        ((TextView) findViewById(R.id.punchTitleText)).setText("In/Out Time");
    } catch (NullPointerException e) {
        Log.e(TAG, "Could not find punchTitleText");
    }

    if (savedInstanceState != null) {
        jobID = savedInstanceState.getLong("job");
        date = new DateTime(savedInstanceState.getLong("date"));
    } else {
        jobID = getIntent().getExtras().getLong("job");
        date = new DateTime(getIntent().getExtras().getLong("date"));
    }

    if (enableLog)
        Log.d(TAG, "JobID: " + jobID);
    if (enableLog)
        Log.d(TAG, "DateTime: " + date);

    Chronos chron = new Chronos(this);
    tasks = chron.getAllTasks();

    @SuppressWarnings("unchecked")
    ArrayAdapter spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tasks);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    taskSpinnerIn.setAdapter(spinnerAdapter);
    taskSpinnerOut.setAdapter(spinnerAdapter);
    //end task

    //set for 24 or 12 hour time
    boolean twentyFourHourTime = DateFormat.is24HourFormat(this);
    TimePicker inTime = (TimePicker) findViewById(R.id.TimePicker1);
    inTime.setIs24HourView(twentyFourHourTime);
    TimePicker outTime = (TimePicker) findViewById(R.id.TimePicker2);
    outTime.setIs24HourView(twentyFourHourTime);

    DateTime now = new DateTime();

    if (enableLog)
        Log.d(TAG, "P1 Current Hour: " + now.getHourOfDay());
    if (enableLog)
        Log.d(TAG, "P1 Current Minute: " + now.getMinuteOfHour());

    inTime.setCurrentHour(now.getHourOfDay());
    inTime.setCurrentMinute(now.getMinuteOfHour());
    taskSpinnerIn.setSelection(0);

    findViewById(R.id.outLayout).setVisibility(View.GONE);

    //close chronos
    chron.close();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //This is a workaround for http://b.android.com/15340 from http://stackoverflow.com/a/5852198/132047
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped);
        bg.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        getSupportActionBar().setBackgroundDrawable(bg);

        BitmapDrawable bgSplit = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped_split_img);
        bgSplit.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        getSupportActionBar().setSplitBackgroundDrawable(bgSplit);
    }

}

From source file:com.linkedin.cubert.utils.FileSystemUtils.java

License:Open Source License

public static List<Path> getDurationPaths(FileSystem fs, Path root, DateTime startDate, DateTime endDate,
        boolean isDaily, int hourStep, boolean errorOnMissing, boolean useHourlyForMissingDaily)
        throws IOException {
    List<Path> paths = new ArrayList<Path>();
    while (endDate.compareTo(startDate) >= 0) {
        Path loc;/*from   w  ww . j  a va 2s . com*/
        if (isDaily)
            loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth());
        else
            loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth(),
                    endDate.getHourOfDay());

        // Check that directory exists, and contains avro files.
        if (fs.exists(loc) && fs.globStatus(new Path(loc, "*" + "avro")).length > 0) {
            paths.add(loc);
        }

        else {

            loc = generateDatedPath(new Path(root.getParent(), "hourly"), endDate.getYear(),
                    endDate.getMonthOfYear(), endDate.getDayOfMonth());
            if (isDaily && useHourlyForMissingDaily && fs.exists(loc)) {
                for (FileStatus hour : fs.listStatus(loc)) {
                    paths.add(hour.getPath());
                }
            }

            else if (errorOnMissing) {
                throw new RuntimeException("Missing directory " + loc.toString());
            }

        }
        if (hourStep == 24)
            endDate = endDate.minusDays(1);
        else
            endDate = endDate.minusHours(hourStep);
    }
    return paths;
}