Example usage for org.joda.time LocalDateTime getHourOfDay

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

Introduction

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

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:de.jpaw.bonaparte.util.DayTime.java

License:Apache License

/** Converts the time portion of a LocalTime or localDateTime into a number in the format HHMMSSMMM. */
static public int timeAsInt(LocalDateTime when) {
    return when.getMillisOfSecond() + 1000 * when.getSecondOfMinute() + 100000 * when.getMinuteOfHour()
            + 10000000 * when.getHourOfDay();
}

From source file:ee.ut.soras.ajavtV2.Main.java

License:Open Source License

/**
 *    Loob etteantud sisends6ne p6hjal referentsaja: granulaarsuste <i>aasta, kuu, kuupaev,
 *    tund, minut</i> vaartuste j2rjendi. Kui sisends6ne ei rahulda regulaaravaldisi 
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}/</code> vi
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}/</code> , tagastatakse null.
 *    Kui sisends6ne on null, luuakse referentsaja j2rjend minuti-t2psusega hetkeaja p6hjal.
 *    <br><br> /*  ww w  . j a va  2 s  .  c o m*/
 *    Tagastatud j2rjendis on granulaarsuste vaartused j2rjekorras 
 *    <i>aasta, kuu, kuupaev, tund, minut</i>. 
 */
public static String[] looSonePohjalReferentsAeg(String sone) {
    if (sone != null) {
        if (sone.matches("[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}")) {
            // 1) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens1 = new StringTokenizer(sone, "-:T");
            while (tokens1.hasMoreTokens()) {
                String s = (String) tokens1.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            return kalendriValjadeVaartused;
        } else if (sone.matches("^[0-9X]{4}-[0-9X]{2}-[0-9X]{2}$")) {
            // 2) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens2 = new StringTokenizer(sone, "-");
            while (tokens2.hasMoreTokens()) {
                String s = (String) tokens2.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            // Viimased (kellaaja osa) ongi selle mustri puhul teadmata
            kalendriValjadeVaartused[3] = "XX";
            kalendriValjadeVaartused[4] = "XX";
            return kalendriValjadeVaartused;
        }
        return null;
    } else {
        // 2) Kui sisends6ne puudub v6i ei vasta etteantud mustrile, loome uue
        // referentsaja, milleks saab hetkeaeg
        LocalDateTime hetkeAeg = new LocalDateTime();
        String[] kalendriValjadeVaartused = new String[5];
        kalendriValjadeVaartused[0] = String.valueOf(hetkeAeg.getYear());
        kalendriValjadeVaartused[1] = String.valueOf(hetkeAeg.getMonthOfYear());
        kalendriValjadeVaartused[2] = String.valueOf(hetkeAeg.getDayOfMonth());
        kalendriValjadeVaartused[3] = String.valueOf(hetkeAeg.getHourOfDay());
        kalendriValjadeVaartused[4] = String.valueOf(hetkeAeg.getMinuteOfHour());
        for (int i = 1; i < kalendriValjadeVaartused.length; i++) {
            if (kalendriValjadeVaartused[i].length() == 1) {
                kalendriValjadeVaartused[i] = "0" + kalendriValjadeVaartused[i];
            }
        }
        return kalendriValjadeVaartused;
    }
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }//from   w w  w.j  av a  2  s. co m
    LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate();
    emailCampaign.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(emailCampaign.getRecurrence(),
            emailCampaign.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(emailCampaign.getRecurrence(),
                emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = emailCampaign.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);

    emailCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.emailCampaignRepository.saveAndFlush(emailCampaign);
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override/*from   www  . ja  v a  2 s.c  om*/
public CommandProcessingResult activateEmailCampaign(Long campaignId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();

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

    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);

    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }

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

    emailCampaign.activate(currentUser, fmt, activationDate);

    this.emailCampaignRepository.saveAndFlush(emailCampaign);

    if (emailCampaign.isDirect()) {
        insertDirectCampaignIntoEmailOutboundTable(emailCampaign.getParamValue(),
                emailCampaign.getEmailSubject(), emailCampaign.getEmailMessage(),
                emailCampaign.getCampaignName(), emailCampaign.getId());
    } else {
        if (emailCampaign.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 (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
                nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                        emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
            } else {
                nextTriggerDate = emailCampaign.getRecurrenceStartDate();
            }
            // to get time of tenant
            final LocalDateTime getTime = emailCampaign.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);

            emailCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
            this.emailCampaignRepository.saveAndFlush(emailCampaign);
        }
    }

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

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override/*  ww  w .  j a  va 2s .  c  o m*/
public CommandProcessingResult reactivateEmailCampaign(final Long campaignId, JsonCommand command) {

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

    final AppUser currentUser = this.context.authenticatedUser();

    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);

    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate reactivationDate = command.localDateValueOfParameterNamed("activationDate");
    emailCampaign.reactivate(currentUser, fmt, reactivationDate);
    if (emailCampaign.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 (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                    emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = emailCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = emailCampaign.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);

        emailCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
        this.emailCampaignRepository.saveAndFlush(emailCampaign);
    }

    return new CommandProcessingResultBuilder() //
            .withEntityId(emailCampaign.getId()) //
            .build();

}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.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 w  w. j  a v a 2s . c  o  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:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override//from  ww  w . ja v  a  2  s.  c  o  m
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.getParamValue(), smsCampaign.getMessage(),
                smsCampaign.getCampaignName());
    } 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();
}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

@Transactional
@Override/*from  w ww.  java 2 s  .c  o  m*/
public CommandProcessingResult reactivateSmsCampaign(final Long campaignId, JsonCommand command) {

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

    final AppUser currentUser = this.context.authenticatedUser();

    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 reactivationDate = command.localDateValueOfParameterNamed("activationDate");
    smsCampaign.reactivate(currentUser, fmt, reactivationDate);
    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);
    }

    return new CommandProcessingResultBuilder() //
            .withEntityId(smsCampaign.getId()) //
            .build();

}

From source file:org.apache.isis.applib.fixturescripts.clock.ClockFixture.java

License:Apache License

@Override
protected void execute(ExecutionContext ec) {

    // can only be used in the context of integration tests
    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }//from   w  w  w.j  av  a2  s.co  m
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // check that some value has been set
    checkParam("date", ec, String.class);

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));
}

From source file:org.apache.isis.applib.fixturescripts.clock.TickingClockFixture.java

License:Apache License

private void setTo(final String date) {

    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }// w  w w.  j a v  a  2  s.c  om
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));

}