1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution11/src/org/apidesign/apifest08/currency/DateUtil.java Fri Oct 17 17:34:40 2008 +0200
1.3 @@ -0,0 +1,68 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +import java.util.Date;
1.7 +
1.8 +/**
1.9 + * Date util helper class.
1.10 + * @author ked
1.11 + */
1.12 +final class DateUtil {
1.13 +
1.14 + private DateUtil() {};
1.15 +
1.16 + static boolean isInRange(Date instant, Date from, Date till) {
1.17 + if ((from == null || instant.equals(from) || instant.after(from)) &&
1.18 + (till == null || instant.before(till))) {
1.19 + return true;
1.20 + } else {
1.21 + return false;
1.22 + }
1.23 + }
1.24 +
1.25 + static boolean isRangesOverlapping(Date fromA, Date tillA, Date fromB, Date tillB) {
1.26 + if ((fromA == null && tillA == null) || (fromB == null && tillB == null)) {
1.27 + return true;
1.28 + }
1.29 + if (fromA != null && isInRange(fromA, fromB, tillB)) {
1.30 + return true;
1.31 + }
1.32 + if (tillA != null && !tillA.equals(fromB) && isInRange(tillA, fromB, tillB)) {
1.33 + return true;
1.34 + }
1.35 + if (fromB != null && isInRange(fromB, fromA, tillA)) {
1.36 + return true;
1.37 + }
1.38 + if (tillB != null && !tillB.equals(fromA) && isInRange(tillB, fromA, tillA)) {
1.39 + return true;
1.40 + }
1.41 + return false;
1.42 + }
1.43 +
1.44 + static Date getRangesIntersectionBottom(Date fromA, Date fromB) {
1.45 + if (fromA == null) {
1.46 + return fromB;
1.47 + }
1.48 + if (fromB == null) {
1.49 + return fromA;
1.50 + }
1.51 + if (fromA.after(fromB)) {
1.52 + return fromA;
1.53 + } else {
1.54 + return fromB;
1.55 + }
1.56 + }
1.57 +
1.58 + static Date getRangesIntersectionTop(Date tillA, Date tillB) {
1.59 + if (tillA == null) {
1.60 + return tillB;
1.61 + }
1.62 + if (tillB == null) {
1.63 + return tillA;
1.64 + }
1.65 + if (tillA.before(tillB)) {
1.66 + return tillA;
1.67 + } else {
1.68 + return tillB;
1.69 + }
1.70 + }
1.71 +}