eu.future.earth.gwt.client.date.DateUtils Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2007 Future Earth, [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package eu.future.earth.gwt.client.date;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import eu.future.earth.client.date.DateNoTimeZone;
public final class DateUtils {
private DateUtils() {
super();
}
public static Calendar createCalendar() {
Calendar result = new GregorianCalendar();
result.setFirstDayOfWeek(Calendar.MONDAY);
result.setMinimalDaysInFirstWeek(4);
return result;
}
public static int countDays(DateRenderer> theRenderer) {
int count = 0;
if (theRenderer.showDay(Calendar.MONDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.TUESDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.WEDNESDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.THURSDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.FRIDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.SATURDAY)) {
count++;
}
if (theRenderer.showDay(Calendar.SUNDAY)) {
count++;
}
return count;
}
@SuppressWarnings("deprecation")
public static boolean isSameDay(Date one, Date two) {
if (one == null || two == null) {
return false;
}
if (one.getYear() != two.getYear()) {
return false;
}
if (one.getMonth() != two.getMonth()) {
return false;
}
if (one.getDate() != two.getDate()) {
return false;
}
return true;
}
@SuppressWarnings("deprecation")
public static boolean isSameDay(Date one, DateNoTimeZone two) {
if (one == null || two == null) {
return false;
}
if (one.getYear() != two.getYear()) {
return false;
}
if (one.getMonth() != two.getMonth()) {
return false;
}
if (one.getDate() != two.getDate()) {
return false;
}
return true;
}
public static boolean isSameDay(DateNoTimeZone one, DateNoTimeZone two) {
if (one == null || two == null) {
return false;
}
if (one.getYear() != two.getYear()) {
return false;
}
if (one.getMonth() != two.getMonth()) {
return false;
}
if (one.getDate() != two.getDate()) {
return false;
}
return true;
}
public static boolean isSameDay(Calendar one, Calendar two) {
if (one != null && two != null) {
if (one.get(Calendar.YEAR) == two.get(Calendar.YEAR) && one.get(Calendar.DAY_OF_YEAR) == two.get(Calendar.DAY_OF_YEAR)) {
return true;
}
}
return false;
}
/**
* This methis checks wheter the Date are the Same or the second is the 00 minute on the next day.
*
* @param one
* - The First Date
* @param two
* - The Second date
* @return
*/
@SuppressWarnings("deprecation")
public static boolean isSameDayOrNextDayZeroMinutes(Date one, Date two) {
if (one == null || two == null) {
return false;
}
if (one.getYear() != two.getYear()) {
return false;
}
if (one.getMonth() != two.getMonth()) {
return false;
}
if (one.getDate() != two.getDate()) {
return !nextDayZeroMinutes(one, two);
}
return true;
}
/**
* Check if the second date is the first minute of the next day.
*
* @param one
* The first date.
* @param two
* The second date.
* @return true of false
*/
@SuppressWarnings("deprecation")
public static boolean nextDayZeroMinutes(Date one, Date two) {
if (one == null || two == null) {
return false;
}
if (one.getYear() != two.getYear()) {
return false;
}
if (one.getMonth() != two.getMonth()) {
return false;
}
if ((one.getDate() + 1) != two.getDate()) {
return false;
}
if (0 != two.getHours() || 0 != two.getMinutes()) {
return false;
}
return true;
}
/**
* Check if the second date is the first minute of the next day.
*
* @param one
* The first date.
* @param two
* The second date.
* @return true of false
*/
@SuppressWarnings("deprecation")
public static boolean zeroMinutes(Date two) {
if (two == null) {
return false;
}
if (0 == two.getHours() && 0 == two.getMinutes()) {
return true;
}
return false;
}
}