source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDate.java@ 8699

Last change on this file since 8699 was 5800, checked in by cs025, 21 years ago

Adding gs3build

  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1package org.greenstone.gsdl3.gs3build.metadata;
2
3public class METSDate
4{
5 String era;
6 String year;
7 String month;
8 String day;
9 String hour;
10 String minute;
11 String second;
12 String timezone;
13
14 public void METSDate(String string)
15 { String date;
16
17 int timeAt = string.indexOf('T');
18
19 // if we've got a time signature, get it
20 if (timeAt >= 0) {
21 // get the date for later use
22 date = string.substring(0, timeAt);
23
24 // extract the time string
25 String time = string.substring(timeAt+1);
26
27 // check for time zone usage - currently '+' and '-' only...
28 int zoneAt = time.indexOf('+');
29 if (zoneAt == -1) {
30 zoneAt = time.indexOf('-');
31 }
32 if (zoneAt >= 0) {
33 this.timezone = time.substring(zoneAt);
34 time = time.substring(0, zoneAt);
35 }
36
37 // finally, divide into hours, minutes etc.
38 int hourAt = time.indexOf(':');
39 if (hourAt >= 0) {
40 this.hour = time.substring(0, hourAt);
41
42 time = time.substring(hourAt+1);
43 int minuteAt = time.indexOf(':');
44 if (minuteAt >= 0)
45 { this.minute = time.substring(0, minuteAt);
46 this.second = time.substring(minuteAt+1);
47 }
48 else
49 { this.minute = time;
50 this.second = null;
51 }
52 }
53 }
54 else
55 { this.timezone = null;
56 this.hour = null;
57 this.minute = null;
58 this.second = null;
59
60 date = string;
61 }
62
63 // get the era
64 int prefixEnds = 0;
65 while (!Character.isDigit(date.charAt(prefixEnds)))
66 { prefixEnds ++;
67 }
68
69 if (prefixEnds != 0) {
70 this.era = date.substring(0, prefixEnds);
71 date = date.substring(prefixEnds);
72 }
73 else {
74 this.era = null;
75 }
76
77 // finally, get the date
78
79 // now try dividing up by '-'
80 int yearAt = date.indexOf('-');
81 if (yearAt >= 0) {
82 this.year = date.substring(0, yearAt);
83 date = date.substring(yearAt+1);
84
85 int monthAt = date.indexOf('-');
86 if (monthAt >= 0) {
87 this.month = date.substring(0, monthAt);
88 this.day = date.substring(monthAt+1);
89 }
90 else {
91 this.month = date;
92 this.day = null;
93 }
94 }
95 else {
96 // try dividing by YYYYMMDD - any part of which may be missing...
97 if (date.length() >= 4) {
98 this.year = date.substring(0, 4);
99 if (date.length() >= 6) {
100 this.month = date.substring(4, 6);
101 this.day = date.substring(6);
102 }
103 else {
104 this.month = date.substring(4);
105 this.day = null;
106 }
107 }
108 // we just have a day in this case...
109 else {
110 this.year = date;
111 this.month = null;
112 this.day = null;
113 }
114 }
115 }
116
117 public String toString()
118 { if (this.year == null) {
119 return "";
120 }
121
122 StringBuffer buffer = new StringBuffer();
123
124 if (this.era != null) {
125 buffer.append(era);
126 }
127 buffer.append(year);
128 if (this.month != null) {
129 buffer.append("-");
130 buffer.append(this.month);
131 if (this.day != null) {
132 buffer.append("-");
133 buffer.append(this.day);
134
135 if (this.hour != null) {
136 buffer.append("T");
137 buffer.append(this.hour);
138 buffer.append(":");
139 buffer.append(this.minute);
140 if (this.second != null) {
141 buffer.append(":");
142 buffer.append(this.second);
143
144 if (this.timezone != null) {
145 buffer.append(this.timezone);
146 }
147 }
148 }
149 }
150 }
151 return buffer.toString();
152 }
153}
Note: See TracBrowser for help on using the repository browser.