List of usage examples for org.joda.time Period getHours
public int getHours()
From source file:influent.server.utilities.DateTimeParser.java
License:MIT License
/** * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html#normalizedStandard() *///from w w w .ja v a 2s .com public static Period normalize(Period period) { long millis = period.getMillis(); millis += period.getSeconds() * DateTimeConstants.MILLIS_PER_SECOND; millis += period.getMinutes() * DateTimeConstants.MILLIS_PER_MINUTE; millis += period.getHours() * DateTimeConstants.MILLIS_PER_HOUR; millis += period.getDays() * DateTimeConstants.MILLIS_PER_DAY; millis += period.getWeeks() * DateTimeConstants.MILLIS_PER_WEEK; Period result = new Period(millis, DateTimeUtils.getPeriodType(PeriodType.standard()), ISOChronology.getInstanceUTC()); int years = period.getYears(); int months = period.getMonths(); if (years != 0 || months != 0) { years = FieldUtils.safeAdd(years, months / 12); months = months % 12; if (years != 0) { result = result.withYears(years); } if (months != 0) { result = result.withMonths(months); } } return result; }
From source file:io.coala.xml.XmlUtil.java
License:Apache License
/** * @param period/*from www . jav a2 s. c o m*/ * @return a JAXP {@link Duration} */ public static Duration toDuration(final Period period) { return getDatatypeFactory().newDuration(true, period.getYears(), period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds()); }
From source file:io.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion.java
License:Apache License
private static boolean periodIsDayMultiple(final Period period) { return period.getMillis() == 0 && period.getSeconds() == 0 && period.getMinutes() == 0 && period.getHours() == 0 && (period.getDays() > 0 || period.getWeeks() > 0 || period.getMonths() > 0 || period.getYears() > 0); }
From source file:io.ehdev.android.drivingtime.view.dialog.InsertOrEditRecordDialog.java
License:Open Source License
private void setTimeViewParameters(View view) { Period duration = drivingRecord.getDurationOfDriving().toPeriod(); ((TimePicker) view.findViewById(R.id.durationPicker)).setIs24HourView(true); ((TimePicker) view.findViewById(R.id.durationPicker)).setCurrentHour(duration.getHours()); ((TimePicker) view.findViewById(R.id.durationPicker)).setCurrentMinute(duration.getMinutes()); }
From source file:io.ehdev.android.drivingtime.view.dialog.InsertOrEditTaskDialog.java
License:Open Source License
private void setTimeViewParameters(View view) { Period duration = drivingTask.getRequiredHours().toPeriod(); ((TimePicker) view.findViewById(R.id.durationPicker)).setIs24HourView(true); ((TimePicker) view.findViewById(R.id.durationPicker)).setCurrentHour(duration.getHours()); ((TimePicker) view.findViewById(R.id.durationPicker)).setCurrentMinute(duration.getMinutes()); }
From source file:io.konig.dao.core.ChartWriterFactory.java
License:Apache License
private Formatter categoryFormatter(Chart chart) { ChartCategories categories = chart.getCategories(); if (categories instanceof DateTimeCategories) { String pattern = null;//from w ww .j a v a 2s . c o m DateTimeCategories c = (DateTimeCategories) categories; Period period = c.getInterval(); if (period.getHours() > 0) { pattern = HOUR; } else if (period.getDays() > 0) { pattern = DATE; } else if (period.getMonths() > 0) { pattern = MONTH; } else if (period.getYears() > 0) { pattern = YEAR; } else { throw new RuntimeException("Unsupported period: " + period.toString()); } return new TemporalFormatter(DateTimeFormat.forPattern(pattern)); } if (categories instanceof LabelCategories) { return new Formatter() { @Override public String format(Object value) { return (String) value; } }; } // TODO: support other categories throw new RuntimeException("Category type not supported"); }
From source file:net.longfalcon.view.DateView.java
License:Open Source License
public Period roundPeriod(Period period) { int fieldCount = 0; int years = period.getYears(); int months = period.getMonths(); int weeks = period.getWeeks(); int days = period.getDays(); int hours = period.getHours(); int minutes = period.getMinutes(); int seconds = period.getSeconds(); if (years > 0) { fieldCount++;/*from www .j a v a 2 s. co m*/ } if (months > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(years, months, 0, 0, 0, 0, 0, 0); } if (weeks > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, months, weeks, 0, 0, 0, 0, 0); } if (days > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, weeks, days, 0, 0, 0, 0); } if (hours > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, 0, days, hours, 0, 0, 0); } if (minutes > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, 0, 0, hours, minutes, 0, 0); } return new Period(0, 0, 0, 0, 0, minutes, seconds, 0); }
From source file:net.longfalcon.web.AdminJobConfigController.java
License:Open Source License
private JobConfigView getJobConfigView(JobConfig jobConfig) { JobConfigView jobConfigView = new JobConfigView(); jobConfigView.setJobKey(jobConfig.getJobName()); String jobFrequency = jobConfig.getJobFrequency(); jobConfigView.setFrequencyType(jobFrequency); if (JobConfigKeys.FREQ_PERIODIC.equals(jobFrequency)) { int periodMillis = Integer.parseInt(jobConfig.getFrequencyConfig()); Period period = new Period(periodMillis); jobConfigView.setPeriodHours(period.getHours()); jobConfigView.setPeriodMins(period.getMinutes()); } else if (JobConfigKeys.FREQ_SCHEDULED.equals(jobFrequency)) { String crontab = jobConfig.getFrequencyConfig(); String[] cronElements = crontab.split(" "); // there will be six. String minutesString = cronElements[1]; jobConfigView.setScheduledMinutes(Integer.parseInt(minutesString)); String hoursString = cronElements[2]; jobConfigView.setScheduledHours(Integer.parseInt(hoursString)); // skip the others right now String days = cronElements[5]; // days are always set as comma list in Newsj. String[] dayList = days.split(","); for (String dayString : dayList) { if ("1".equals(dayString)) { jobConfigView.setSunday(true); }// w ww . j a v a 2s. com if ("2".equals(dayString)) { jobConfigView.setMonday(true); } if ("3".equals(dayString)) { jobConfigView.setTuesday(true); } if ("4".equals(dayString)) { jobConfigView.setWednesday(true); } if ("5".equals(dayString)) { jobConfigView.setThursday(true); } if ("6".equals(dayString)) { jobConfigView.setFriday(true); } if ("7".equals(dayString)) { jobConfigView.setSaturday(true); } } } return jobConfigView; }
From source file:nu.yona.app.utils.AppUtils.java
/** * Gets time for otp./*from w ww .j a v a2 s. c o m*/ * * @param time the time * @return the time for otp */ public static Pair<String, Long> getTimeForOTP(String time) { try { StringBuffer buffer = new StringBuffer(); long totalTime = 0; Period period = new Period(time); if (period.getHours() > 0) { totalTime += period.getHours() * AppConstant.ONE_SECOND * 60 * 60; buffer.append(YonaApplication.getAppContext().getString(R.string.hours, period.getHours() + "")); } if (period.getMinutes() > 0) { totalTime += period.getMinutes() * AppConstant.ONE_SECOND * 60; buffer.append(YonaApplication.getAppContext().getString(R.string.minute, period.getMinutes() + "")); } if (period.getSeconds() > 0) { totalTime += period.getSeconds() * AppConstant.ONE_SECOND; buffer.append( YonaApplication.getAppContext().getString(R.string.seconds, period.getSeconds() + "")); } return Pair.create(buffer.toString(), totalTime); } catch (Exception e) { AppUtils.reportException(AppUtils.class.getSimpleName(), e, Thread.currentThread()); } return Pair.create(time, (long) 0); }
From source file:nz.co.gregs.dbvolution.databases.definitions.DBDefinition.java
License:Apache License
/** * Creates a string representation of a DateRepeat from the Period * * @param interval the interval to be transformed into a DateRepeat. * @return a DateRpeat as an SQL string//from w w w .ja v a 2s .c o m */ public String transformPeriodIntoDateRepeat(Period interval) { StringBuilder str = new StringBuilder(); str.append("'").append(DateRepeatExpression.INTERVAL_PREFIX); str.append(interval.getYears()).append(DateRepeatExpression.YEAR_SUFFIX); str.append(interval.getMonths()).append(DateRepeatExpression.MONTH_SUFFIX); str.append(interval.getDays() + (interval.getWeeks() * 7)).append(DateRepeatExpression.DAY_SUFFIX); str.append(interval.getHours()).append(DateRepeatExpression.HOUR_SUFFIX); str.append(interval.getMinutes()).append(DateRepeatExpression.MINUTE_SUFFIX); str.append(interval.getSeconds()).append(DateRepeatExpression.SECOND_SUFFIX); str.append("'"); return str.toString(); }