1 package ca.uhn.fhir.model.primitive;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.Date;
24 import java.util.TimeZone;
25
26 import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
27 import ca.uhn.fhir.model.api.annotation.DatatypeDef;
28 import ca.uhn.fhir.model.api.annotation.SimpleSetter;
29
30 @DatatypeDef(name = "dateTime")
31 public class DateTimeDt extends BaseDateTimeDt {
32
33
34
35
36 public static final TemporalPrecisionEnum DEFAULT_PRECISION = TemporalPrecisionEnum.SECOND;
37
38
39
40
41 public DateTimeDt() {
42 super();
43 }
44
45
46
47
48 @SimpleSetter(suffix = "WithSecondsPrecision")
49 public DateTimeDt(@SimpleSetter.Parameter(name = "theDate") Date theDate) {
50 setValue(theDate);
51 setPrecision(DEFAULT_PRECISION);
52 setTimeZone(TimeZone.getDefault());
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66 @SimpleSetter
67 public DateTimeDt(@SimpleSetter.Parameter(name = "theDate") Date theDate, @SimpleSetter.Parameter(name = "thePrecision") TemporalPrecisionEnum thePrecision) {
68 setValue(theDate);
69 setPrecision(thePrecision);
70 setTimeZone(TimeZone.getDefault());
71 }
72
73
74
75
76 public DateTimeDt(String theValue) {
77 setValueAsString(theValue);
78 }
79
80 @Override
81 boolean isPrecisionAllowed(TemporalPrecisionEnum thePrecision) {
82 switch (thePrecision) {
83 case YEAR:
84 case MONTH:
85 case DAY:
86 case SECOND:
87 case MILLI:
88 return true;
89 default:
90 return false;
91 }
92 }
93
94
95
96
97 public static DateTimeDt withCurrentTime() {
98 return new DateTimeDt(new Date(), TemporalPrecisionEnum.SECOND);
99 }
100
101 }