Example usage for org.joda.time LocalDateTime getMinuteOfHour

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

Introduction

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

Prototype

public int getMinuteOfHour() 

Source Link

Document

Get the minute of hour field value.

Usage

From source file:ch.icclab.cyclops.util.DateTimeUtil.java

License:Open Source License

/**
 * Generates the 1 hr time range (from and to) by computing the present server time
 *
 * @return dateTime A string consisting of from and to dateTime entries
 *//*from w  ww . j a  v  a2s . co  m*/
public String[] getRange() {
    String from, to;
    String sMonth = null;
    String sDay = null;
    String stHour = null;
    String sHour = null;
    String sMin = null;
    String sSec = null;
    int year, month, day, hour, min, sec, tHour;
    String[] dateTime = new String[2];

    LocalDateTime currentDate = LocalDateTime.now();
    year = currentDate.getYear();
    month = currentDate.getMonthOfYear();
    if (month <= 9) {
        sMonth = "0" + month;
    } else {
        sMonth = month + "";
    }
    day = currentDate.getDayOfMonth();
    if (day <= 9) {
        sDay = "0" + day;
    } else {
        sDay = day + "";
    }
    hour = currentDate.getHourOfDay();
    if (hour <= 9) {
        sHour = "0" + hour;
    } else {
        sHour = hour + "";
    }
    min = currentDate.getMinuteOfHour();
    if (min <= 9) {
        sMin = "0" + min;
    } else {
        sMin = min + "";
    }
    sec = currentDate.getSecondOfMinute();
    if (sec <= 9) {
        sSec = "0" + sec;
    } else {
        sSec = sec + "";
    }

    to = year + "-" + sMonth + "-" + sDay + "T" + sHour + ":" + sMin + ":" + sSec + "Z";
    Date dateTo = getDate(to);
    //Converting to in UTC
    to = getString(dateTo);
    long sensuFrequency = Loader.getSettings().getSchedulerSettings().getSchedulerFrequency();

    long fromTimestamp = dateTo.getTime() - sensuFrequency * 1000;
    Date fromDate = new Date(fromTimestamp);

    from = getString(fromDate);

    dateTime[0] = to;
    dateTime[1] = from;

    return dateTime;
}

From source file:cherry.goods.util.JodaTimeUtil.java

License:Apache License

/**
 * @param ldtm ???{@link LocalDateTime}/*w ww  . ja v  a  2s  . com*/
 * @return ?????{@link Calendar}(?)????????
 */
public static Calendar getCalendar(LocalDateTime ldtm) {
    Calendar cal = Calendar.getInstance();
    cal.set(ldtm.getYear(), ldtm.getMonthOfYear() - 1, ldtm.getDayOfMonth(), ldtm.getHourOfDay(),
            ldtm.getMinuteOfHour(), ldtm.getSecondOfMinute());
    cal.set(MILLISECOND, ldtm.getMillisOfSecond());
    return cal;
}

From source file:com.axelor.apps.hr.service.timesheet.TimesheetServiceImpl.java

License:Open Source License

public String computeFullName(Timesheet timesheet) {

    User timesheetUser = timesheet.getUser();
    LocalDateTime createdOn = timesheet.getCreatedOn();

    if (timesheetUser != null && createdOn != null) {
        return timesheetUser.getFullName() + " " + createdOn.getDayOfMonth() + "/" + createdOn.getMonthOfYear()
                + "/" + timesheet.getCreatedOn().getYear() + " " + createdOn.getHourOfDay() + ":"
                + createdOn.getMinuteOfHour();
    } else if (timesheetUser != null) {
        return timesheetUser.getFullName() + " N" + timesheet.getId();
    } else {// w  ww .j  av  a  2  s  .c  om
        return "N" + timesheet.getId();
    }
}

From source file:com.ephemeraldreams.gallyshuttle.ui.events.PrepareAlarmReminderEvent.java

License:Apache License

private void setAlarmCalendar() {
    LocalDateTime alarmDateTime = DateUtils.parseToLocalDateTime(time);
    alarmDateTime = alarmDateTime.minusMinutes(prefReminderLength);
    hour = alarmDateTime.getHourOfDay();
    minute = alarmDateTime.getMinuteOfHour();
}

From source file:com.ephemeraldreams.gallyshuttle.ui.MainFragment.java

License:Apache License

private void setScheduleId() {
    LocalDateTime now = LocalDateTime.now();
    int hour = now.getHourOfDay();
    int minute = now.getMinuteOfHour();
    if (hour >= 21 || (hour == 0 && minute <= 15)) {
        scheduleId = R.array.late_night_stations;
    } else {/*  w  w w.  jav  a  2s. c o  m*/
        int day = now.getDayOfWeek();
        switch (day) {
        case SATURDAY:
        case SUNDAY:
            scheduleId = R.array.weekend_stations;
            break;
        default:
            scheduleId = R.array.continuous_stations;
            break;
        }
    }
}

From source file:com.google.gerrit.server.config.ScheduleConfig.java

License:Apache License

private static long initialDelay(Config rc, String section, String subsection, String keyStartTime,
        DateTime now, long interval) {
    long delay = MISSING_CONFIG;
    String start = rc.getString(section, subsection, keyStartTime);
    try {//from ww  w. j a v a  2s . com
        if (start != null) {
            DateTimeFormatter formatter;
            MutableDateTime startTime = now.toMutableDateTime();
            try {
                formatter = ISODateTimeFormat.hourMinute();
                LocalTime firstStartTime = formatter.parseLocalTime(start);
                startTime.hourOfDay().set(firstStartTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
            } catch (IllegalArgumentException e1) {
                formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
                LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
                startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
                startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
            }
            startTime.secondOfMinute().set(0);
            startTime.millisOfSecond().set(0);
            long s = startTime.getMillis();
            long n = now.getMillis();
            delay = (s - n) % interval;
            if (delay <= 0) {
                delay += interval;
            }
        } else {
            log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section,
                    keyStartTime));
        }
    } catch (IllegalArgumentException e2) {
        log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime),
                e2);
        delay = INVALID_CONFIG;
    }
    return delay;
}

From source file:com.gs.fw.common.mithra.databasetype.SybaseIqNativeDatabaseType.java

License:Apache License

@Override
public Timestamp getTimestampFromResultSet(ResultSet rs, int pos, TimeZone timeZone) throws SQLException {
    Timestamp localTs = rs.getTimestamp(pos);
    if (localTs == null) {
        return null;
    }//from   www . ja va  2  s . co m
    LocalDateTime ldt = new LocalDateTime(localTs.getTime());

    Calendar utcCal = getCalendarInstance();
    utcCal.set(Calendar.YEAR, ldt.getYear());
    utcCal.set(Calendar.MONTH, ldt.getMonthOfYear() - 1);
    utcCal.set(Calendar.DAY_OF_MONTH, ldt.getDayOfMonth());
    utcCal.set(Calendar.HOUR_OF_DAY, ldt.getHourOfDay());
    utcCal.set(Calendar.MINUTE, ldt.getMinuteOfHour());
    utcCal.set(Calendar.SECOND, ldt.getSecondOfMinute());
    utcCal.set(Calendar.MILLISECOND, ldt.getMillisOfSecond());
    Timestamp utcTs = new Timestamp(utcCal.getTimeInMillis());
    return MithraTimestamp.zConvertTimeForReadingWithUtcCalendar(utcTs, timeZone);
}

From source file:com.gs.fw.common.mithra.util.Time.java

License:Apache License

public static Time withSqlTime(java.sql.Time sqlTime) {
    if (sqlTime == null)
        return null;

    LocalDateTime localDateTime = new LocalDateTime(sqlTime.getTime());
    return Time.withMillis(localDateTime.getHourOfDay(), localDateTime.getMinuteOfHour(),
            localDateTime.getSecondOfMinute(), localDateTime.getMillisOfSecond());
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }//from  w  ww . j  ava 2 s. co  m
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    // calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future
     * date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means
                                                                  // next
                                                                  // run
                                                                  // time is
                                                                  // in the
                                                                  // past
                                                                  // calculate
                                                                  // a new
                                                                  // future
                                                                  // date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

@Transactional
@Override//from   w w  w.j  av a2 s .  c  om
public CommandProcessingResult activateSmsCampaign(Long campaignId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();

    this.smsCampaignValidator.validateActivation(command.json());

    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);

    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate");

    smsCampaign.activate(currentUser, fmt, activationDate);

    this.smsCampaignRepository.saveAndFlush(smsCampaign);

    if (smsCampaign.isDirect()) {
        insertDirectCampaignIntoSmsOutboundTable(smsCampaign);
    } else if (smsCampaign.isSchedule()) {

        /**
         * if recurrence start date is in the future calculate next trigger
         * date if not use recurrence start date us next trigger date when
         * activating
         */
        LocalDate nextTriggerDate = null;
        if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                    smsCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = smsCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();

        final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
        final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

        smsCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
        this.smsCampaignRepository.saveAndFlush(smsCampaign);
    }

    /*
     * if campaign is direct insert campaign message into sms outbound table
     * else if its a schedule create a job process for it
     */
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withEntityId(smsCampaign.getId()) //
            .build();
}