List of usage examples for org.joda.time LocalDate toDateTime
public DateTime toDateTime(LocalTime time, DateTimeZone zone)
From source file:com.ning.billing.beatrix.util.InvoiceChecker.java
License:Apache License
public void checkChargedThroughDate(final UUID subscriptionId, final LocalDate expectedLocalCTD, final CallContext context) { try {/*from w w w. j ava 2 s. co m*/ final Subscription subscription = entitlementApi.getSubscriptionFromId(subscriptionId, context); if (expectedLocalCTD == null) { assertNull(subscription.getChargedThroughDate()); } else { final DateTime expectedCTD = expectedLocalCTD.toDateTime( new LocalTime(subscription.getStartDate().getMillis(), DateTimeZone.UTC), DateTimeZone.UTC); final String msg = String.format( "Checking CTD for subscription %s : expectedLocalCTD = %s => expectedCTD = %s, got %s", subscriptionId, expectedLocalCTD, expectedCTD, subscription.getChargedThroughDate()); log.info(msg); assertNotNull(subscription.getChargedThroughDate()); assertTrue(subscription.getChargedThroughDate().compareTo(expectedCTD) == 0, msg); } } catch (EntitlementUserApiException e) { fail("Failed to retrieve subscription for " + subscriptionId); } }
From source file:com.sheepdog.mashmesh.models.VolunteerProfile.java
License:Apache License
private List<Interval> getAvailableIntervals(DateTime aroundDateTime) { List<Interval> intervals = new ArrayList<Interval>(); Map<Integer, DateTime> adjacentDays = new HashMap<Integer, DateTime>(3); // Construct a map from days of the week to DateTimes representing adjacent days. for (int i = -1; i <= 1; i++) { DateTime dateTime = aroundDateTime.plusDays(i); int day = dateTime.getDayOfWeek(); adjacentDays.put(day, dateTime); }// ww w . j a va 2s . c om // Construct Intervals from time periods in adjacent days. for (AvailableTimePeriod availableTimePeriod : availableTimePeriods) { if (adjacentDays.containsKey(availableTimePeriod.getDay())) { LocalDate date = adjacentDays.get(availableTimePeriod.getDay()).toLocalDate(); DateTime start = date.toDateTime(availableTimePeriod.getStartTime(), aroundDateTime.getZone()); DateTime end = date.toDateTime(availableTimePeriod.getEndTime(), aroundDateTime.getZone()); // Allow 00:00 - 00:00 to express 00:00 - 24:00 as we can't serialize a // LocalTime representing 24:00. if (end.compareTo(start) <= 0) { end = end.plusDays(1); } intervals.add(new Interval(start, end)); } } // Sort the Intervals so that adjacent time periods abut. Assumes that intervals don't overlap. Collections.sort(intervals, new Comparator<Interval>() { @Override public int compare(Interval i1, Interval i2) { return new Long(i1.getStartMillis()).compareTo(i2.getStartMillis()); } }); // Merge abutting intervals together List<Interval> mergedIntervals = new ArrayList<Interval>(); Interval lastInterval = null; for (Interval interval : intervals) { if (lastInterval != null && lastInterval.abuts(interval)) { mergedIntervals.remove(mergedIntervals.size() - 1); interval = lastInterval.withEnd(interval.getEnd()); } lastInterval = interval; mergedIntervals.add(interval); } return mergedIntervals; }
From source file:com.sonicle.webtop.calendar.bol.ORecurrence.java
License:Open Source License
public void updateUntilDate(LocalDate localDate, LocalTime localTime, DateTimeZone timezone) { Recur recur = getRecur();/*w ww .j a v a 2 s .c om*/ ICal4jUtils.setRecurUntilDate(recur, localDate.toDateTime(localTime, timezone)); setRule(recur.toString()); setUntilDate(localDate.toDateTimeAtStartOfDay(timezone).plusDays(1)); }
From source file:com.sonicle.webtop.calendar.CalendarManager.java
License:Open Source License
private <T> List<T> calculateRecurringInstances(Connection con, RecurringInstanceMapper<T> instanceMapper, DateTime rangeFrom, DateTime rangeTo, DateTimeZone userTimezone, int limit) throws WTException { RecurrenceDAO recDao = RecurrenceDAO.getInstance(); RecurrenceBrokenDAO recbDao = RecurrenceBrokenDAO.getInstance(); ArrayList<T> instances = new ArrayList<>(); int eventId = instanceMapper.getEventId(); DateTime eventStart = instanceMapper.getEventStartDate(); DateTime eventEnd = instanceMapper.getEventEndDate(); DateTimeZone eventTimezone = instanceMapper.getEventTimezone(); LocalTime eventStartTime = eventStart.withZone(eventTimezone).toLocalTime(); LocalTime eventEndTime = eventEnd.withZone(eventTimezone).toLocalTime(); try {/*ww w.jav a 2s. com*/ // Retrieves reccurence and broken dates (if any) ORecurrence orec = recDao.selectByEvent(con, eventId); if (orec == null) { logger.warn("Unable to retrieve recurrence for event [{}]", eventId); } else { if (rangeFrom == null) rangeFrom = orec.getStartDate(); if (rangeTo == null) rangeTo = orec.getStartDate().plusYears(1); Recur recur = orec.getRecur(); if (recur == null) throw new WTException("Unable to parse rrule [{}]", orec.getRule()); Map<LocalDate, ORecurrenceBroken> obrecs = recbDao.selectByEventRecurrence(con, eventId, orec.getRecurrenceId()); DateList dates = ICal4jUtils.calculateRecurrenceSet(recur, orec.getStartDate(), eventTimezone, rangeFrom, rangeTo, limit); Iterator it = dates.iterator(); while (it.hasNext()) { net.fortuna.ical4j.model.Date dt = (net.fortuna.ical4j.model.Date) it.next(); LocalDate recurringDate = ICal4jUtils.toJodaLocalDate(dt, eventTimezone); if (obrecs.containsKey(recurringDate)) continue; // Skip broken date... DateTime start = recurringDate.toDateTime(eventStartTime, eventTimezone).withZone(userTimezone); DateTime end = recurringDate.toDateTime(eventEndTime, eventTimezone).withZone(userTimezone); String key = EventKey.buildKey(eventId, eventId, recurringDate); instances.add(instanceMapper.createInstance(key, start, end)); } } } catch (DAOException ex) { throw wrapException(ex); } return instances; }
From source file:com.sonicle.webtop.core.dal.IMMessageDAO.java
License:Open Source License
public List<OIMMessage> selectByProfileChatDate(Connection con, UserProfileId profile, String chatJid, LocalDate date, DateTimeZone timezone, boolean byDelivery) throws DAOException { DSLContext dsl = getDSL(con);//ww w . ja v a 2 s . c o m final DateTime ts1 = date.toDateTime(LocalTime.MIDNIGHT, timezone); final DateTime ts2 = ts1.plusDays(1); return dsl .select(IM_MESSAGES.ID, IM_MESSAGES.DOMAIN_ID, IM_MESSAGES.CHAT_JID, IM_MESSAGES.SENDER_JID, IM_MESSAGES.SENDER_RESOURCE, IM_MESSAGES.TIMESTAMP, IM_MESSAGES.DELIVERY_TIMESTAMP, IM_MESSAGES.ACTION, IM_MESSAGES.TEXT, IM_MESSAGES.DATA, IM_MESSAGES.MESSAGE_UID, IM_MESSAGES.STANZA_ID) .from(IM_MESSAGES) .where(IM_MESSAGES.DOMAIN_ID.equal(profile.getDomainId()) .and(IM_MESSAGES.USER_ID.equal(profile.getUserId())) .and(IM_MESSAGES.CHAT_JID.equal(chatJid)).and(timestampCondition(byDelivery, ts1, ts2))) .orderBy(IM_MESSAGES.TIMESTAMP.asc(), IM_MESSAGES.ID.asc()).fetchInto(OIMMessage.class); }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTideTideDataProvider.java
License:Open Source License
@Override public List<TidePredictionDay> getTidePredictionDay(Port port) throws TideDataProviderException { HttpGet getRequest;/*w w w. ja va2 s . c o m*/ try { getRequest = new EasyTideHttpGet( mUriBuilder.buildGetPredictionUri(mGetTidePredictionUrlSuffix, port.getExternalId(), 3)); HttpResponse response = mHttpClient.execute(getRequest); Parser parser = getHtmlParser(response); // Parse the timezone information NodeList nodeList = new NodeList(); NodeFilter filter = new AndFilter(new TagNameFilter("SPAN"), new HasAttributeFilter("ID", "PredictionSummary1_lblZoneTimeOffset")); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } if (nodeList.size() != 1) { throw new TideDataProviderException("Couldn't retrieve the time zone information"); } String timeZoneString = ((TagNode) nodeList.elementAt(0)).getChildren().elementAt(0).getText(); Matcher timeZoneMatcher = mTimeZoneRegexPattern.matcher(timeZoneString); // attempt the common case first int hoursOffset; int minutesOffset; if (timeZoneMatcher.matches()) { hoursOffset = Integer.parseInt(timeZoneMatcher.group(1)); final String minutesString = timeZoneMatcher.group(3); minutesOffset = (minutesString == null) ? 0 : Integer.parseInt(minutesString); } else if (timeZoneString.compareTo("Port predictions (Standard Local Time) are equal to UTC") == 0) { // is already UTC hoursOffset = 0; minutesOffset = 0; } else { throw new TideDataProviderException( "Couldn't parse the time zone information from: ".concat(timeZoneString)); } final DateTimeZone timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset); // Parse the current day (today) information nodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("SPAN"), new HasAttributeFilter("ID", "PredictionSummary1_lblPredictionStart")); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } if (nodeList.size() != 1) { throw new TideDataProviderException("Couldn't retrieve today's date"); } String todayString = ((TagNode) nodeList.elementAt(0)).getChildren().elementAt(0).getText(); Matcher todayMatcher = mTodayRegexPattern.matcher(todayString); LocalDate localDate; if (todayMatcher.matches()) { localDate = LocalDate.parse(todayMatcher.group(1).concat(todayMatcher.group(2)), mLocalDateFormatter); } else { throw new TideDataProviderException( "Couldn't parse the time zone information from: ".concat(timeZoneString)); } // Get each of the HW,LW tables nodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TABLE"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable first"), new OrFilter(new HasAttributeFilter("CLASS", "HWLWTable last"), new HasAttributeFilter("CLASS", "HWLWTable first last"))))); parser.reset(); for (NodeIterator e = parser.elements(); e.hasMoreNodes();) { e.nextNode().collectInto(nodeList, filter); } int numDays = nodeList.size(); final List<TidePredictionDay> tidePredictionDays = new ArrayList<TidePredictionDay>(numDays); for (int nDay = 0; nDay < numDays; ++nDay) { final TagNode tagNode = (TagNode) nodeList.elementAt(nDay); final TidePredictionDay tidePredictionDay = new TidePredictionDay(); tidePredictionDay.setLocalDate(localDate); // LWHW NodeList lwHwNodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TH"), new HasAttributeFilter("CLASS", "HWLWTableHWLWCellPrintFriendly")); tagNode.collectInto(lwHwNodeList, filter); // Times and Heights NodeList timeHeightNodeList = new NodeList(); filter = new AndFilter(new TagNameFilter("TD"), new HasAttributeFilter("CLASS", "HWLWTableCellPrintFriendly")); tagNode.collectInto(timeHeightNodeList, filter); int numTides = lwHwNodeList.size(); for (int nTide = 0; nTide < numTides; ++nTide) { final TidePrediction tidePrediction = new TidePrediction(); tidePrediction.setTidePredictionType(TidePredictionType .fromString(lwHwNodeList.elementAt(nTide).getChildren().elementAt(0).getText())); // Set the time LocalTime localTime; String localTimeString = timeHeightNodeList.elementAt(nTide).getChildren().elementAt(0) .getText(); if (localTimeString != null && !localTimeString.isEmpty() && localTimeString.compareTo(" ") != 0) { if (localTimeString.contains("*")) { localTimeString = localTimeString.replace("*", ""); tidePrediction.setIsEstimate(true); } localTime = mLocalTimeFormatter.parseLocalTime(localTimeString); } else { // we can't really make out that this is a sensible prediction // so don't include this continue; } final DateTime dateTime = localDate.toDateTime(localTime, timeZone); tidePrediction.setUtcTime(dateTime); // Set the height where possible final String heightString = timeHeightNodeList.elementAt(nTide + numTides).getChildren() .elementAt(0).getText(); if (heightString != null && !heightString.isEmpty()) { Matcher tideHeightMatcher = mTideHeightRegexPattern.matcher(heightString); if (tideHeightMatcher.matches()) { tidePrediction.setHeight(Float.parseFloat(tideHeightMatcher.group(1))); } } // Tie both together tidePrediction.setTidePredictionDay(tidePredictionDay); tidePredictionDay.getTidePredictions().add(tidePrediction); } tidePredictionDays.add(tidePredictionDay); localDate = localDate.plusDays(1); } return tidePredictionDays; } catch (URISyntaxException e) { throw new TideDataProviderException(e); } catch (IOException e) { throw new TideDataProviderException(e); } catch (ParseException e) { throw new TideDataProviderException(e); } catch (ParserException e) { throw new TideDataProviderException(e); } }
From source file:org.killbill.billing.util.timezone.DateAndTimeZoneContext.java
License:Apache License
public DateTime computeUTCDateTimeFromLocalDate(final LocalDate invoiceItemEndDate) { ///*from ww w . ja v a 2 s .c om*/ // Since we create the targetDate for next invoice using the date from the notificationQ, we need to make sure // that this datetime once transformed into a LocalDate points to the correct day. // // All we need to do is figure if the transformation from DateTime (point in time) to LocalDate (date in account time zone) // changed the day; if so, when we recompute a UTC date from LocalDate (date in account time zone), we can simply chose a reference // time and apply the offset backward to end up on the right day // // We use clock.getUTCNow() to get the offset with account timezone but that may not be correct // when we transition from standard time and daylight saving time. We could end up with a result // that is slightly in advance and therefore results in a null invoice. // We will fix that by re-inserting ourselves in the notificationQ if we detect that there is no invoice // and yet the subscription is recurring and not cancelled. // return invoiceItemEndDate.toDateTime(referenceTime, DateTimeZone.UTC).plusDays(-offsetFromUtc); }
From source file:org.kuali.kpme.tklm.leave.block.LeaveBlockBo.java
License:Educational Community License
public void setBeginDate(Date beginDate) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginDate); LocalTime localTime = new LocalTime(beginTimestamp); beginTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis()); }
From source file:org.kuali.kpme.tklm.time.timeblock.TimeBlock.java
License:Educational Community License
public void setBeginDate(Date beginDate) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginDate); LocalTime localTime = new LocalTime(beginTimestamp); beginTimestamp = localDate.toDateTime(localTime, dateTime.getZone()).toDate(); }
From source file:org.kuali.kpme.tklm.time.timeblock.TimeBlock.java
License:Educational Community License
public void setBeginTime(Time beginTime) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginTimestamp); LocalTime localTime = new LocalTime(beginTime); beginTimestamp = localDate.toDateTime(localTime, dateTime.getZone()).toDate(); }