List of usage examples for org.joda.time DateTime withZone
public DateTime withZone(DateTimeZone newZone)
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 {/*from w w w .j a v a 2 s. c o m*/ // 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.calendar.rpt.AbstractAgenda.java
License:Open Source License
private boolean startsInDay(DateTimeZone utz, DateTime dayDate, DateTime eventStartDate) { return DateTimeUtils.startsInDay(dayDate, eventStartDate.withZone(utz)); }
From source file:com.sonicle.webtop.calendar.rpt.AbstractAgenda.java
License:Open Source License
private boolean endsInDay(DateTimeZone utz, DateTime dayDate, DateTime eventEndDate) { return DateTimeUtils.endsInDay(dayDate, eventEndDate.withZone(utz)); }
From source file:com.sonicle.webtop.calendar.rpt.AbstractAgenda.java
License:Open Source License
private boolean isInDay(DateTimeZone utz, DateTime dayDate, DateTime eventStartDate, DateTime eventEndDate) { // NB: dayDate must be at midnight!! DateTime dayDateTo = dayDate.plusDays(1); DateTime start = eventStartDate.withZone(utz); DateTime end = eventEndDate.withZone(utz); if (startsInDay(utz, dayDate, eventStartDate)) return true; if (endsInDay(utz, dayDate, eventEndDate)) return true; if ((start.compareTo(dayDate) <= 0) && (end.compareTo(dayDateTo) >= 0)) return true; return false; }
From source file:com.sonicle.webtop.calendar.Service.java
License:Open Source License
private DateTimeRange buildSearchRange(DateTime now, DateTimeZone timezone) { return new DateTimeRange(now.withZone(timezone).minusMonths(6).withTimeAtStartOfDay(), now.withZone(timezone).plusMonths(6).withTimeAtStartOfDay()); }
From source file:com.sonicle.webtop.core.CoreManager.java
License:Open Source License
public List<LocalDate> listIMMessageDates(String chatJid, int year, DateTimeZone timezone) throws WTException { IMMessageDAO imesDao = IMMessageDAO.getInstance(); ArrayList<LocalDate> items = new ArrayList<>(); Connection con = null;//from w w w . j a v a 2 s .c o m try { con = WT.getCoreConnection(); List<DateTime> dts = imesDao.selectDatesByProfileChatYear(con, getTargetProfileId(), chatJid, year, timezone); for (DateTime dt : dts) { items.add(dt.withZone(timezone).toLocalDate()); } return items; } catch (SQLException | DAOException ex) { throw new WTException(ex, "DB error"); } finally { DbUtils.closeQuietly(con); } }
From source file:com.sonicle.webtop.core.xmpp.ChatMessage.java
License:Open Source License
public static String buildUniqueId(EntityBareJid fromUser, String fromUserResource, DateTime timestamp) { CompositeId cid = new CompositeId(fromUser, fromUserResource, new Long(timestamp.withZone(DateTimeZone.UTC).getMillis())); return DigestUtils.md5Hex(cid.toString()); }
From source file:com.sonicle.webtop.core.xmpp.XMPPClient.java
License:Open Source License
private boolean joinMuc(final MultiUserChat muc, final DateTime lastSeenActivity) { try {//from w w w .j ava 2 s . c om logger.debug("Joining group chat [{}, {}]", muc.getRoom().toString(), lastSeenActivity); DiscussionHistory mucHistory = new DiscussionHistory(); if (lastSeenActivity != null) { DateTime now = new DateTime(DateTimeZone.UTC); Seconds seconds = Seconds.secondsBetween(lastSeenActivity.withZone(DateTimeZone.UTC), now); mucHistory.setSeconds(Math.abs(seconds.getSeconds())); } muc.join(userNickname, null, mucHistory, SmackConfiguration.getDefaultReplyTimeout()); return true; } catch (SmackException | XMPPException | InterruptedException ex) { logger.error("Error joining group chat", ex); return false; } }
From source file:com.sonicle.webtop.tasks.TasksManager.java
License:Open Source License
public List<BaseReminder> getRemindersToBeNotified(DateTime now) { ArrayList<BaseReminder> alerts = new ArrayList<>(); HashMap<UserProfileId, Boolean> byEmailCache = new HashMap<>(); TaskDAO dao = TaskDAO.getInstance(); Connection con = null;/*from w w w .ja va 2 s .c o m*/ try { con = WT.getConnection(SERVICE_ID); con.setAutoCommit(false); DateTime now12 = now.plusHours(14); List<VTask> tasks = dao.viewExpridedForUpdateByUntil(con, now12); DateTime profileNow = null, profileReminderDate = null; for (VTask task : tasks) { UserProfile.Data ud = WT.getUserData(task.getCategoryProfileId()); profileNow = now.withZone(ud.getTimeZone()); profileReminderDate = task.getReminderDate().withZone(DateTimeZone.UTC) .withZoneRetainFields(ud.getTimeZone()); if (profileReminderDate.isAfter(profileNow)) continue; if (!byEmailCache.containsKey(task.getCategoryProfileId())) { TasksUserSettings us = new TasksUserSettings(SERVICE_ID, task.getCategoryProfileId()); boolean bool = us.getTaskReminderDelivery().equals(TasksSettings.TASK_REMINDER_DELIVERY_EMAIL); byEmailCache.put(task.getCategoryProfileId(), bool); } int ret = dao.updateRemindedOn(con, task.getTaskId(), now); if (ret != 1) continue; if (byEmailCache.get(task.getCategoryProfileId())) { alerts.add( createTaskReminderAlertEmail(ud.toProfileI18n(), task, ud.getPersonalEmailAddress())); } else { alerts.add(createTaskReminderAlertWeb(ud.toProfileI18n(), task, profileReminderDate)); } } DbUtils.commitQuietly(con); } catch (Exception ex) { logger.error("Error collecting reminder alerts", ex); } finally { DbUtils.closeQuietly(con); } return alerts; }
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static Date convertToUTC(Date date) { DateTime time = new DateTime(date.getTime()); DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime utc = time.withZone(dtZone); return utc.toDate(); }