List of usage examples for com.liferay.portal.kernel.util StringPool UTC
String UTC
To view the source code for com.liferay.portal.kernel.util StringPool UTC.
Click Source Link
From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java
License:Open Source License
protected Calendar toCalendar(DateProperty date, TimeZone timeZone, boolean timeZoneSensitive) { Calendar cal = null;//w ww. ja v a 2s. co m if (isICal4jDateOnly(date)) { cal = Calendar.getInstance(); } else if (!timeZoneSensitive) { cal = Calendar.getInstance(TimeZoneUtil.getTimeZone(StringPool.UTC)); } else { cal = Calendar.getInstance(timeZone); } return cal; }
From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java
License:Open Source License
protected TZSRecurrence toRecurrence(RRule rRule, Calendar startDate) { Recur recur = rRule.getRecur();/*from w ww . j a va 2s . com*/ Calendar recStartCal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC)); recStartCal.setTime(startDate.getTime()); TZSRecurrence recurrence = new TZSRecurrence(recStartCal, new com.liferay.portal.kernel.cal.Duration(1, 0, 0, 0)); recurrence.setWeekStart(Calendar.SUNDAY); if (recur.getInterval() > 1) { recurrence.setInterval(recur.getInterval()); } Calendar until = Calendar.getInstance(TimeZoneUtil.getTimeZone(StringPool.UTC)); String frequency = recur.getFrequency(); if (recur.getUntil() != null) { until.setTime(recur.getUntil()); recurrence.setUntil(until); } else if (rRule.getValue().indexOf("COUNT") >= 0) { until.setTimeInMillis(startDate.getTimeInMillis()); int addField = 0; if (Recur.DAILY.equals(frequency)) { addField = Calendar.DAY_OF_YEAR; } else if (Recur.WEEKLY.equals(frequency)) { addField = Calendar.WEEK_OF_YEAR; } else if (Recur.MONTHLY.equals(frequency)) { addField = Calendar.MONTH; } else if (Recur.YEARLY.equals(frequency)) { addField = Calendar.YEAR; } int addAmount = recurrence.getInterval() * recur.getCount(); until.add(addField, addAmount); until.add(Calendar.DAY_OF_YEAR, -1); recurrence.setUntil(until); } if (Recur.DAILY.equals(frequency)) { recurrence.setFrequency(Recurrence.DAILY); List<DayAndPosition> dayPosList = new ArrayList<DayAndPosition>(); Iterator<WeekDay> itr = recur.getDayList().iterator(); while (itr.hasNext()) { WeekDay weekDay = itr.next(); dayPosList.add(new DayAndPosition(toCalendarWeekDay(weekDay), 0)); } if (!dayPosList.isEmpty()) { recurrence.setByDay(dayPosList.toArray(new DayAndPosition[dayPosList.size()])); } } else if (Recur.WEEKLY.equals(frequency)) { recurrence.setFrequency(Recurrence.WEEKLY); List<DayAndPosition> dayPosList = new ArrayList<DayAndPosition>(); Iterator<WeekDay> itr = recur.getDayList().iterator(); while (itr.hasNext()) { WeekDay weekDay = itr.next(); dayPosList.add(new DayAndPosition(toCalendarWeekDay(weekDay), 0)); } if (!dayPosList.isEmpty()) { recurrence.setByDay(dayPosList.toArray(new DayAndPosition[dayPosList.size()])); } } else if (Recur.MONTHLY.equals(frequency)) { recurrence.setFrequency(Recurrence.MONTHLY); Iterator<Integer> monthDayListItr = recur.getMonthDayList().iterator(); if (monthDayListItr.hasNext()) { Integer monthDay = monthDayListItr.next(); recurrence.setByMonthDay(new int[] { monthDay.intValue() }); } Iterator<WeekDay> dayListItr = recur.getDayList().iterator(); if (dayListItr.hasNext()) { WeekDay weekDay = dayListItr.next(); DayAndPosition[] dayPos = { new DayAndPosition(toCalendarWeekDay(weekDay), weekDay.getOffset()) }; recurrence.setByDay(dayPos); } } else if (Recur.YEARLY.equals(frequency)) { recurrence.setFrequency(Recurrence.YEARLY); } return recurrence; }
From source file:com.liferay.timetracking.timesheet.service.impl.WorkDayLocalServiceImpl.java
License:Open Source License
/** * NOTE FOR DEVELOPERS:/*from www . ja v a 2 s. co m*/ * * Never reference this interface directly. Always use {@link com.liferay.timetracking.timesheet.service.WorkDayLocalServiceUtil} to access the work day local service. */ @Override public WorkDay addWorkDay(long userId, long companyId, long startTime, long endTime, long dayOfYearId, int break_, ServiceContext serviceContext) throws PortalException, SystemException { validate(userId, companyId, startTime, endTime, break_); Date now = new Date(); long workDayId = counterLocalService.increment(); WorkDay workDay = workDayPersistence.create(workDayId); workDay.setCompanyId(companyId); workDay.setUserId(userId); workDay.setUserName(UserLocalServiceUtil.getUserById(userId).getFullName()); workDay.setCreateDate(now); workDay.setModifiedDate(now); TimeZone timeZone = TimeZoneUtil.getTimeZone(StringPool.UTC); Calendar start = CalendarFactoryUtil.getCalendar(timeZone); start.setTimeInMillis(startTime); workDay.setDayOfYearId(dayOfYearId); workDay.setBreak_(break_); workDay.setStartTime(start.getTime()); if (endTime != 0) { Calendar end = CalendarFactoryUtil.getCalendar(timeZone); end.setTimeInMillis(endTime); workDay.setEndTime(end.getTime()); } workDayPersistence.update(workDay); return workDay; }
From source file:com.liferay.timetracking.timesheet.service.impl.WorkDayLocalServiceImpl.java
License:Open Source License
@Override public List<WorkDay> getWorkDays(long userId, long startTime, long endTime) throws SystemException { TimeZone timeZone = TimeZoneUtil.getTimeZone(StringPool.UTC); Calendar startCalendar = CalendarFactoryUtil.getCalendar(timeZone); startCalendar.setTimeInMillis(startTime); Calendar endCalendar = CalendarFactoryUtil.getCalendar(timeZone); endCalendar.setTimeInMillis(endTime); List<WorkDay> workDays = workDayFinder.findByStartTimeEndTimeUserId(startCalendar.getTime(), endCalendar.getTime(), userId); return workDays; }
From source file:com.liferay.timetracking.timesheet.service.impl.WorkDayLocalServiceImpl.java
License:Open Source License
@Override public WorkDay updateWorkDay(long userId, long workDayId, long startTime, long endTime, long dayOfYearId, int break_, ServiceContext serviceContext) throws PortalException, SystemException { Date now = new Date(); WorkDay workDay = workDayPersistence.findByPrimaryKey(workDayId); validate(userId, workDay.getCompanyId(), startTime, endTime, break_); workDay.setUserId(userId);/*www . j a v a 2 s.c o m*/ workDay.setUserName(UserLocalServiceUtil.getUserById(userId).getFullName()); workDay.setModifiedDate(now); TimeZone timeZone = TimeZoneUtil.getTimeZone(StringPool.UTC); Calendar start = CalendarFactoryUtil.getCalendar(timeZone); start.setTimeInMillis(startTime); Calendar end = CalendarFactoryUtil.getCalendar(timeZone); end.setTimeInMillis(endTime); workDay.setEndTime(end.getTime()); workDay.setBreak_(break_); workDay.setStartTime(start.getTime()); workDay.setDayOfYearId(dayOfYearId); workDayPersistence.update(workDay); return workDay; }
From source file:com.liferay.util.cal.Recurrence.java
License:Open Source License
/** * Method setDtStart/*from w w w . j a v a 2 s . c o m*/ */ public void setDtStart(Calendar start) { int oldStart; if (dtStart != null) { oldStart = dtStart.getFirstDayOfWeek(); } else { oldStart = Calendar.MONDAY; } if (start == null) { dtStart = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC)); dtStart.setTime(new Date(0L)); } else { dtStart = (Calendar) start.clone(); dtStart.clear(Calendar.ZONE_OFFSET); dtStart.clear(Calendar.DST_OFFSET); dtStart.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC)); } dtStart.setMinimalDaysInFirstWeek(4); dtStart.setFirstDayOfWeek(oldStart); }
From source file:com.liferay.util.cal.Recurrence.java
License:Open Source License
/** * Method setDtEnd//from w w w .j a v a2 s . c o m */ public void setDtEnd(Calendar end) { Calendar tempEnd = (Calendar) end.clone(); tempEnd.clear(Calendar.ZONE_OFFSET); tempEnd.clear(Calendar.DST_OFFSET); tempEnd.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC)); duration.setInterval(tempEnd.getTime().getTime() - dtStart.getTime().getTime()); }
From source file:com.liferay.util.cal.Recurrence.java
License:Open Source License
/** * Method setUntil//from www . j av a2 s. c om */ public void setUntil(Calendar u) { if (u == null) { until = null; return; } until = (Calendar) u.clone(); until.clear(Calendar.ZONE_OFFSET); until.clear(Calendar.DST_OFFSET); until.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC)); }
From source file:com.liferay.util.cal.Recurrence.java
License:Open Source License
/** * Method isInRecurrence/* ww w . j a v a 2 s.co m*/ * * @return boolean */ public boolean isInRecurrence(Calendar current, boolean debug) { Calendar myCurrent = (Calendar) current.clone(); // Do all calculations in GMT. Keep other parameters consistent. myCurrent.clear(Calendar.ZONE_OFFSET); myCurrent.clear(Calendar.DST_OFFSET); myCurrent.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC)); myCurrent.setMinimalDaysInFirstWeek(4); myCurrent.setFirstDayOfWeek(dtStart.getFirstDayOfWeek()); if (myCurrent.getTime().getTime() < dtStart.getTime().getTime()) { // The current time is earlier than the start time. if (debug) { System.err.println("current < start"); } return false; } Calendar candidate = getCandidateStartTime(myCurrent); /* Loop over ranges for the duration. */ while (candidate.getTime().getTime() + duration.getInterval() > myCurrent.getTime().getTime()) { if (candidateIsInRecurrence(candidate, debug)) { return true; } /* Roll back to one second previous, and try again. */ candidate.add(Calendar.SECOND, -1); /* Make sure we haven't rolled back to before dtStart. */ if (candidate.getTime().getTime() < dtStart.getTime().getTime()) { if (debug) { System.err.println("No candidates after dtStart"); } return false; } candidate = getCandidateStartTime(candidate); } if (debug) { System.err.println("No matching candidates"); } return false; }
From source file:com.liferay.util.cal.Recurrence.java
License:Open Source License
/** * Method getCandidateStartTime/*from w w w .j ava 2 s . com*/ * * @return Calendar */ public Calendar getCandidateStartTime(Calendar current) { if (dtStart.getTime().getTime() > current.getTime().getTime()) { throw new IllegalArgumentException("Current time before DtStart"); } int minInterval = getMinimumInterval(); Calendar candidate = (Calendar) current.clone(); if (true) { // This block is only needed while this function is public... candidate.clear(Calendar.ZONE_OFFSET); candidate.clear(Calendar.DST_OFFSET); candidate.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC)); candidate.setMinimalDaysInFirstWeek(4); candidate.setFirstDayOfWeek(dtStart.getFirstDayOfWeek()); } if (frequency == NO_RECURRENCE) { candidate.setTime(dtStart.getTime()); return candidate; } reduce_constant_length_field(Calendar.SECOND, dtStart, candidate); reduce_constant_length_field(Calendar.MINUTE, dtStart, candidate); reduce_constant_length_field(Calendar.HOUR_OF_DAY, dtStart, candidate); switch (minInterval) { case DAILY: /* No more adjustments needed */ break; case WEEKLY: reduce_constant_length_field(Calendar.DAY_OF_WEEK, dtStart, candidate); break; case MONTHLY: reduce_day_of_month(dtStart, candidate); break; case YEARLY: reduce_day_of_year(dtStart, candidate); break; } return candidate; }