mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
126098 amukha: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 126058 jkaabimofrad: ACE-5001: Added a utility class to calculate the number of days between the start and end dates, so we could have a single source when dealing with such functionality. Also, changed the RepoUsageComponentImpl class to use this util class. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127841 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
74
source/java/org/alfresco/util/DateUtil.java
Normal file
74
source/java/org/alfresco/util/DateUtil.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.util;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Interval;
|
||||
import org.joda.time.Period;
|
||||
import org.joda.time.PeriodType;
|
||||
|
||||
/**
|
||||
* A utility class for working with dates.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class DateUtil
|
||||
{
|
||||
private DateUtil()
|
||||
{
|
||||
//Private constructor to suppress default constructor for non-instantiability
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of days between start and end dates based on the <b>default</b> timezone.
|
||||
* If the end date is before the start date, the returned value is negative.
|
||||
*
|
||||
* @param startMs start date in milliseconds
|
||||
* @param endMs end date in milliseconds
|
||||
* @return number days between
|
||||
*/
|
||||
public static int calculateDays(long startMs, long endMs)
|
||||
{
|
||||
DateTime startDateTime = new DateTime(startMs).withTimeAtStartOfDay();
|
||||
DateTime endDateTime = new DateTime(endMs).withTimeAtStartOfDay();
|
||||
|
||||
int days;
|
||||
if (endDateTime.isBefore(startDateTime))
|
||||
{
|
||||
Interval interval = new Interval(endDateTime, startDateTime);
|
||||
Period period = interval.toPeriod(PeriodType.days());
|
||||
days = 0 - period.getDays();
|
||||
}
|
||||
else
|
||||
{
|
||||
Interval interval = new Interval(startDateTime, endDateTime);
|
||||
Period period = interval.toPeriod(PeriodType.days());
|
||||
days = period.getDays();
|
||||
}
|
||||
return days;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user