List of usage examples for org.joda.time Hours ONE
Hours ONE
To view the source code for org.joda.time Hours ONE.
Click Source Link
From source file:aDeleteME.DeleteME.java
public static void main(String[] args) { Random random = new Random(); DateTime startTime = new DateTime(random.nextLong()).withMillisOfSecond(0); Minutes minimumPeriod = Minutes.TWO; int minimumPeriodInSeconds = minimumPeriod.toStandardSeconds().getSeconds(); int maximumPeriodInSeconds = Hours.ONE.toStandardSeconds().getSeconds(); Seconds randomPeriod = Seconds.seconds(random.nextInt(maximumPeriodInSeconds - minimumPeriodInSeconds)); DateTime endTime = startTime.plus(minimumPeriod).plus(randomPeriod); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); System.out.println(dateTimeFormatter.print(startTime)); System.out.println(dateTimeFormatter.print(endTime)); }
From source file:com.marand.thinkmed.medications.pharmacist.impl.PharmacistTaskHandlerImpl.java
License:Open Source License
private PrescriptionChangeTypeEnum getPharmacistTherapyChangeType(final String patientId, final DateTime hospitalizationStart, final DateTime when) { if (hospitalizationStart == null) { return PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION; }/*from ww w . j a v a2 s . com*/ return medicationsOpenEhrDao .findMedicationInstructions(patientId, new Interval(hospitalizationStart, Days.THREE), null) .stream().filter(Objects::nonNull).findFirst().map(Pair::getFirst) .map(c -> new Interval(DataValueUtils.getDateTime(c.getCompositionEventContext().getStartTime()), Hours.ONE)) .map(interval -> interval.contains(when) ? PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION : PrescriptionChangeTypeEnum.ADDITION_TO_EXISTING_PRESCRIPTION) .orElse(PrescriptionChangeTypeEnum.NEW_ADMISSION_PRESCRIPTION); }
From source file:controllers.api.DashboardsApiController.java
License:Open Source License
private Duration estimateIntervalStep(String interval) { Duration step;// w ww . j a v a 2 s. c om switch (interval) { case "minute": step = Minutes.ONE.toStandardDuration(); break; case "hour": step = Hours.ONE.toStandardDuration(); break; case "day": step = Days.ONE.toStandardDuration(); break; case "week": step = Weeks.ONE.toStandardDuration(); break; case "month": step = Days.days(31).toStandardDuration(); break; case "quarter": step = Days.days(31 * 3).toStandardDuration(); break; case "year": step = Days.days(365).toStandardDuration(); break; default: throw new IllegalArgumentException("Invalid duration specified: " + interval); } return step; }
From source file:de.geeksfactory.opacclient.reminder.SyncAccountJob.java
License:MIT License
private void updateLibraryConfig() { PreferenceDataSource prefs = new PreferenceDataSource(getContext()); if (prefs.getLastLibraryConfigUpdate() != null && prefs.getLastLibraryConfigUpdate().isAfter(DateTime.now().minus(Hours.ONE))) { Log.d(TAG, "Do not run updateLibraryConfig as last run was less than an hour ago."); return;/*w w w .j a v a 2 s .c o m*/ } WebService service = WebServiceManager.getInstance(); File filesDir = new File(getContext().getFilesDir(), LibraryConfigUpdateService.LIBRARIES_DIR); filesDir.mkdirs(); try { int count = getApp().getUpdateHandler().updateConfig(service, prefs, new LibraryConfigUpdateService.FileOutput(filesDir), new JsonSearchFieldDataSource(getContext())); Log.d(TAG, "updated config for " + String.valueOf(count) + " libraries"); getApp().resetCache(); if (!BuildConfig.DEBUG) { Sentry.getContext().addExtra(OpacClient.SENTRY_DATA_VERSION, prefs.getLastLibraryConfigUpdate().toString()); } } catch (IOException | JSONException ignore) { } }
From source file:de.geeksfactory.opacclient.reminder.SyncAccountService.java
License:MIT License
private void updateLibraryConfig() { PreferenceDataSource prefs = new PreferenceDataSource(this); if (prefs.getLastLibraryConfigUpdate() != null && prefs.getLastLibraryConfigUpdate().isAfter(DateTime.now().minus(Hours.ONE))) { Log.d(NAME, "Do not run updateLibraryConfig as last run was less than an hour ago."); return;/* w ww .ja va2 s . com*/ } WebService service = WebServiceManager.getInstance(); File filesDir = new File(getFilesDir(), LibraryConfigUpdateService.LIBRARIES_DIR); filesDir.mkdirs(); try { int count = ((OpacClient) getApplication()).getUpdateHandler().updateConfig(service, prefs, new LibraryConfigUpdateService.FileOutput(filesDir), new JsonSearchFieldDataSource(this)); Log.d(NAME, "updated config for " + String.valueOf(count) + " libraries"); ((OpacClient) getApplication()).resetCache(); if (!BuildConfig.DEBUG) { ACRA.getErrorReporter().putCustomData("data_version", prefs.getLastLibraryConfigUpdate().toString()); } } catch (IOException | JSONException ignore) { } }
From source file:energy.usef.core.timer.CorePlanboardEventTrigger.java
License:Apache License
/** * Get the local time for the next ptu shift, using the current time and the ptu duration. * * @return the {@link LocalTime} of the next PTU shift. */// w w w . j a v a 2 s . c om private LocalTime getNextPtuShiftTime() { LocalTime now = DateTimeUtil.getCurrentTime(); int ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION); int minutesPerHour = Hours.ONE.toStandardMinutes().getMinutes(); return new LocalTime( (int) ((now.getHourOfDay() + ((now.getMinuteOfHour() / ptuDuration + 1) * ptuDuration / minutesPerHour)) % TimeUnit.DAYS.toHours(1)), ((now.getMinuteOfHour() / ptuDuration + 1) * ptuDuration) % minutesPerHour); }
From source file:energy.usef.core.util.PowerUtil.java
License:Apache License
/** * Transforms a power (Watt) of a PTU to an energy (Watt hour). * * @param power {@link BigInteger} power expressed in Watts * @param ptuDuration PTU duration/*from ww w . ja va 2 s.c o m*/ * @return the energy expressed in Watt hours */ public static BigInteger powerToEnergy(BigInteger power, Integer ptuDuration) { BigDecimal hoursPerPtu = new BigDecimal(Hours.ONE.toStandardMinutes().getMinutes()) .divide(new BigDecimal(ptuDuration), DECIMAL_PRECISION, RoundingMode.HALF_UP); return new BigDecimal(power).divide(hoursPerPtu, DECIMAL_PRECISION, RoundingMode.HALF_UP).toBigInteger(); }
From source file:energy.usef.core.util.PowerUtil.java
License:Apache License
/** * Transforms price for an amount of power (Watt) per ptu into price of one (Mega Watt hour) based on ptu duration. * * @param power (@link BigInteger) power expressed in Watts * @param price (@link BigInteger) price for the power * @param ptuDuration PTU duration (in minutes) * @return the price of one Mega Watt hours (MWh) */// w w w . ja v a 2 s . co m public static BigDecimal wattPricePerPTUToMWhPrice(BigInteger power, BigDecimal price, Integer ptuDuration) { BigDecimal ptusPerHour = new BigDecimal(Hours.ONE.toStandardMinutes().getMinutes()) .divide(new BigDecimal(ptuDuration), DECIMAL_PRECISION, RoundingMode.HALF_UP); if (power.compareTo(BigInteger.ZERO) == 0) { return BigDecimal.ZERO; } else { return price.multiply(new BigDecimal(MEGA_WATT_FACTOR)).multiply(ptusPerHour) .divide(new BigDecimal(power.abs()), DECIMAL_PRECISION, RoundingMode.HALF_UP); } }
From source file:energy.usef.core.util.PowerUtil.java
License:Apache License
/** * Converts the price of a MWh to the price for a Watt during for a PTU. * * @param price {@link BigDecimal} price for 1 MWh. * @param ptuDuration {@link Integer} duration of a PTU in minutes. * @return the price for 1 W during a PTU. *//*from w w w .j a v a 2 s . com*/ public static BigDecimal megaWattHourPriceToWattPricePerPtu(BigDecimal price, Integer ptuDuration) { BigDecimal ptusPerHour = new BigDecimal(Hours.ONE.toStandardMinutes().getMinutes()) .divide(new BigDecimal(ptuDuration), DECIMAL_PRECISION, RoundingMode.HALF_UP); return price.divide(BigDecimal.valueOf(MEGA_WATT_FACTOR).multiply(ptusPerHour), DECIMAL_PRECISION, RoundingMode.HALF_UP); }
From source file:module.mission.domain.NationalMission.java
License:Open Source License
private boolean overlapsMeal(final Interval interval, final DateTime dateTime, final int hour) { final Interval mealTime = new Interval(dateTime.withTime(hour, 0, 0, 0), Hours.ONE); return interval.overlaps(mealTime); }