List of usage examples for org.joda.time DateTime withMillisOfDay
public DateTime withMillisOfDay(int millis)
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Calculates the # of hours in a given day (where day is an * org.joda.time.DateTime)// w w w. jav a 2s . co m * * @param dt * a DateTime instance * @return the number of hours in a day respecting time zones that honor * Daylight Savings (e.g., calculation takes into account transition * days) */ public static int hoursInDay(final DateTime dt) { final DateTime dt0 = dt.withMillisOfDay(0); // Set to start of day final DateTime dt1 = dt0.plusDays(1); // Set to end of day final Hours hours = Hours.hoursBetween(dt0, dt1); return hours.getHours(); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Converts calendar day at midnight in ISO no millis format to an * org.joda.time.DateTime Format employs Market time zone. * * @param day//from ww w. j a va 2 s . c om * an ISO8601 formatted String (non millis) * @return a DateTime instance at midnight in "Market time" */ public static DateTime isoDayToDateTime(final String day) { final DateTimeFormatter fmt = isoFormat.withZone(marketTimeZone); final DateTime parsed = fmt.parseDateTime(day); // set to start of day final DateTime result = parsed.withMillisOfDay(0); return result; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Return the starting day accounting for Hour 00:00:00 being the day after. * The date is coerced into the market time zone before computing the hour * When hour 00 is detected the day is decremented. The returned date has a * time of 00:00:00 in the market time zone. * * @param dt/*from www . j a va 2 s . co m*/ * an org.joda.time.DateTime * @return an org.joda.time.DateTime expressing an operating day */ public static DateTime getOperatingDay(DateTime dt) { dt = dt.withZone(SSTimeUtil.getMarketTimeZone()); if (dt.getHourOfDay() == 0) { dt = dt.minusDays(1); } return dt.withMillisOfDay(0); }
From source file:rapture.dp.invocable.CheckPrerequisiteStep.java
License:Open Source License
private DateTime getDateTime(DateTime dateTime, String dateWithin, String timeNoEarlierThan) { if (!StringUtils.isEmpty(timeNoEarlierThan)) { DateTime hours = getDateTime(timeNoEarlierThan); if (dateTime == null) dateTime = hours;/*from w ww . ja v a 2 s. com*/ else { dateTime = dateTime.withMillisOfDay(hours.getMillisOfDay()).withZone(hours.getZone()); } } if (!StringUtils.isEmpty(dateWithin)) { int number = Integer.valueOf(dateWithin.substring(0, dateWithin.length() - 1)); char dateUnit = dateWithin.charAt(dateWithin.length() - 1); switch (dateUnit) { case 'M': dateTime = dateTime.minusMonths(number); break; case 'W': dateTime = dateTime.minusWeeks(number); break; case 'D': dateTime = dateTime.minusDays(number); break; case 'H': dateTime = dateTime.minusHours(number); break; case 'B': dateTime = USCalendar.minusBusinessDays(dateTime, number); break; default: throw RaptureExceptionFactory.create("Invalid date unit " + dateUnit); } } return dateTime; }