List of usage examples for org.joda.time LocalDateTime getSecondOfMinute
public int getSecondOfMinute()
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 ww w. ja v a 2 s. c om*/ 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 w w . java2 s .c o m * @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.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; }/* ww w . j av a2s.c o 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 www . ja v a2s . c om 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/*w w w. ja v a2s . co 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); } 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:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java
License:Apache License
@Transactional @Override/* w w w.j a v a 2 s . c om*/ 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.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); return new CommandProcessingResultBuilder() // .withEntityId(smsCampaign.getId()) // .build(); }
From source file:com.gst.infrastructure.dataqueries.service.GenericDataServiceImpl.java
License:Apache License
@Override public String generateJsonFromGenericResultsetData(final GenericResultsetData grs) { final StringBuffer writer = new StringBuffer(); writer.append("["); final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders(); final List<ResultsetRowData> data = grs.getData(); List<String> row; Integer rSize;/*from w ww . ja v a 2 s.c o m*/ final String doubleQuote = "\""; final String slashDoubleQuote = "\\\""; String currColType; String currVal; for (int i = 0; i < data.size(); i++) { writer.append("\n{"); row = data.get(i).getRow(); rSize = row.size(); for (int j = 0; j < rSize; j++) { writer.append(doubleQuote + columnHeaders.get(j).getColumnName() + doubleQuote + ": "); currColType = columnHeaders.get(j).getColumnDisplayType(); final String colType = columnHeaders.get(j).getColumnType(); if (currColType == null && colType.equalsIgnoreCase("INT")) { currColType = "INTEGER"; } if (currColType == null && colType.equalsIgnoreCase("VARCHAR")) { currColType = "VARCHAR"; } if (currColType == null && colType.equalsIgnoreCase("DATE")) { currColType = "DATE"; } currVal = row.get(j); if (currVal != null && currColType != null) { if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) { writer.append(currVal); } else { if (currColType.equals("DATE")) { final LocalDate localDate = new LocalDate(currVal); writer.append("[" + localDate.getYear() + ", " + localDate.getMonthOfYear() + ", " + localDate.getDayOfMonth() + "]"); } else if (currColType.equals("DATETIME")) { final LocalDateTime localDateTime = new LocalDateTime(currVal); writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthOfYear() + ", " + localDateTime.getDayOfMonth() + " " + localDateTime.getHourOfDay() + ", " + localDateTime.getMinuteOfHour() + ", " + localDateTime.getSecondOfMinute() + ", " + localDateTime.getMillisOfSecond() + "]"); } else { writer.append( doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote); } } } else { writer.append("null"); } if (j < (rSize - 1)) { writer.append(",\n"); } } if (i < (data.size() - 1)) { writer.append("},"); } else { writer.append("}"); } } writer.append("\n]"); return writer.toString(); }
From source file:com.helger.datetime.xml.PDTXMLConverter.java
License:Apache License
/** * Get the passed object as {@link XMLGregorianCalendar} with date and time. * * @param aBase/* w w w. ja v a 2 s . com*/ * The source object. May be <code>null</code>. * @return <code>null</code> if the parameter is <code>null</code>. */ @Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable final LocalDateTime aBase) { return aBase == null ? null : s_aDTFactory.newXMLGregorianCalendar(aBase.getYear(), aBase.getMonthOfYear(), aBase.getDayOfMonth(), aBase.getHourOfDay(), aBase.getMinuteOfHour(), aBase.getSecondOfMinute(), aBase.getMillisOfSecond(), DatatypeConstants.FIELD_UNDEFINED); }
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(); }