mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-10204 Support for specifying the timezone (rather than just offset) for calendar entries when creating/editing, with tests, and use this to improve all day event storage/detection
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30436 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -279,7 +279,7 @@ public class CalendarServiceImplTest
|
|||||||
c.set(Calendar.SECOND, 0);
|
c.set(Calendar.SECOND, 0);
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
|
|
||||||
// Neither start nor end are at midnight to start
|
// Neither start nor end are at midnight to start with
|
||||||
assertEquals(false, CalendarEntryDTO.isAllDay(entry));
|
assertEquals(false, CalendarEntryDTO.isAllDay(entry));
|
||||||
|
|
||||||
// Set the start to midnight
|
// Set the start to midnight
|
||||||
|
@@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
public class CalendarEntryDTO implements CalendarEntry, Serializable
|
public class CalendarEntryDTO implements CalendarEntry, Serializable
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -7997650453677545845L;
|
private static final long serialVersionUID = -7997650453677545845L;
|
||||||
|
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||||
|
|
||||||
private NodeRef nodeRef;
|
private NodeRef nodeRef;
|
||||||
private NodeRef containerNodeRef;
|
private NodeRef containerNodeRef;
|
||||||
@@ -275,10 +277,9 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable
|
|||||||
* on a day, and ending at midnight.
|
* on a day, and ending at midnight.
|
||||||
*
|
*
|
||||||
* For a single day event, the start and end dates should be
|
* For a single day event, the start and end dates should be
|
||||||
* the same, and the times for both are midnight.
|
* the same, and the times for both are UTC midnight.
|
||||||
* For a multi day event, the start and end times are midnight,
|
* For a multi day event, the start and end times are UTC midnight,
|
||||||
* for the first and last days respectively.
|
* for the first and last days respectively.
|
||||||
* TODO Timezones!
|
|
||||||
*/
|
*/
|
||||||
public static boolean isAllDay(CalendarEntry entry)
|
public static boolean isAllDay(CalendarEntry entry)
|
||||||
{
|
{
|
||||||
@@ -288,20 +289,37 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Calendar start = Calendar.getInstance();
|
// As of 4.0, all-day events use UTC midnight for consistency
|
||||||
Calendar end = Calendar.getInstance();
|
Calendar startUTC = Calendar.getInstance();
|
||||||
start.setTime(entry.getStart());
|
Calendar endUTC = Calendar.getInstance();
|
||||||
end.setTime(entry.getEnd());
|
startUTC.setTime(entry.getStart());
|
||||||
|
endUTC.setTime(entry.getEnd());
|
||||||
|
startUTC.setTimeZone(UTC);
|
||||||
|
endUTC.setTimeZone(UTC);
|
||||||
|
|
||||||
if (start.get(Calendar.HOUR_OF_DAY) == 0 &&
|
// Pre-4.0, the midnights were local time...
|
||||||
start.get(Calendar.MINUTE) == 0 &&
|
Calendar startLocal = Calendar.getInstance();
|
||||||
start.get(Calendar.SECOND) == 0 &&
|
Calendar endLocal = Calendar.getInstance();
|
||||||
end.get(Calendar.HOUR_OF_DAY) == 0 &&
|
startLocal.setTime(entry.getStart());
|
||||||
end.get(Calendar.MINUTE) == 0 &&
|
endLocal.setTime(entry.getEnd());
|
||||||
end.get(Calendar.SECOND) == 0)
|
|
||||||
|
// Check for midnight, first in UTC then again in Local time
|
||||||
|
Calendar[] starts = new Calendar[] { startUTC, startLocal };
|
||||||
|
Calendar[] ends = new Calendar[] { endUTC, endLocal };
|
||||||
|
for(int i=0; i<starts.length; i++)
|
||||||
{
|
{
|
||||||
// Both midnight, counts as all day
|
Calendar start = starts[i];
|
||||||
return true;
|
Calendar end = ends[i];
|
||||||
|
if (start.get(Calendar.HOUR_OF_DAY) == 0 &&
|
||||||
|
start.get(Calendar.MINUTE) == 0 &&
|
||||||
|
start.get(Calendar.SECOND) == 0 &&
|
||||||
|
end.get(Calendar.HOUR_OF_DAY) == 0 &&
|
||||||
|
end.get(Calendar.MINUTE) == 0 &&
|
||||||
|
end.get(Calendar.SECOND) == 0)
|
||||||
|
{
|
||||||
|
// Both at midnight, counts as all day
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In any other case, it isn't an all-day
|
// In any other case, it isn't an all-day
|
||||||
|
Reference in New Issue
Block a user