1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.instance.data;
|
11
|
|
|
12
|
|
import java.math.BigDecimal;
|
13
|
|
|
14
|
|
import org.jbind.xml.core.data.CompareResult;
|
15
|
|
import org.jbind.xml.core.data.ITime;
|
16
|
|
import org.jbind.xml.core.data.ITimeZone;
|
17
|
|
|
18
|
|
/**
|
19
|
|
* Represents an instance in time. Time instances are always normalized to UTC.
|
20
|
|
*/
|
21
|
|
public class Time extends PointInTime implements ITime {
|
22
|
|
|
23
|
|
/**
|
24
|
|
* Creates a time object. If a time zone is specified then the time is adjusted
|
25
|
|
* correspondingly.
|
26
|
|
*/
|
27
|
7
|
public static ITime create(int anHour, int aMinute, int aSecond, BigDecimal aFraction, ITimeZone aTimeZone) {
|
28
|
7
|
Time t = new Time(anHour, aMinute, aSecond, aFraction, null != aTimeZone);
|
29
|
7
|
return (null != aTimeZone) ? TimeHelper.add(t, aTimeZone) : t;
|
30
|
|
}
|
31
|
|
|
32
|
11
|
public Time(int anHour, int aMinute, int aSecond, BigDecimal aFraction, boolean aHadTimeZone) {
|
33
|
11
|
super(anHour, aMinute, aSecond, aFraction, aHadTimeZone);
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public CompareResult compareTo(ITime aTime) {
|
37
|
0
|
if ((hadTimeZone() && !aTime.hadTimeZone()) || (!hadTimeZone() && aTime.hadTimeZone())) {
|
38
|
0
|
return CompareResult.UNDETERMINED;
|
39
|
|
}
|
40
|
0
|
if (myHour < aTime.getHour()) {
|
41
|
0
|
return CompareResult.LESS;
|
42
|
0
|
} else if (myHour > aTime.getHour()) {
|
43
|
0
|
return CompareResult.GREATER;
|
44
|
|
}
|
45
|
0
|
if (myMinute < aTime.getMinute()) {
|
46
|
0
|
return CompareResult.LESS;
|
47
|
0
|
} else if (myMinute > aTime.getMinute()) {
|
48
|
0
|
return CompareResult.GREATER;
|
49
|
|
}
|
50
|
0
|
if (mySecond < aTime.getSecond()) {
|
51
|
0
|
return CompareResult.LESS;
|
52
|
0
|
} else if (mySecond > aTime.getSecond()) {
|
53
|
0
|
return CompareResult.GREATER;
|
54
|
|
}
|
55
|
0
|
if ((null == myFraction) && (null != aTime.getFraction())) {
|
56
|
0
|
return CompareResult.LESS;
|
57
|
0
|
} else if ((null != myFraction) && (null == aTime.getFraction())) {
|
58
|
0
|
return CompareResult.GREATER;
|
59
|
|
}
|
60
|
0
|
int c = (null == myFraction) ? 0 : myFraction.compareTo(aTime.getFraction());
|
61
|
0
|
return (c < 0) ? CompareResult.LESS : (c > 0) ? CompareResult.GREATER : CompareResult.EQUAL;
|
62
|
|
}
|
63
|
|
|
64
|
|
}
|
65
|
|
|