package org.greenstone.gsdl3.gs3build.metadata; public class METSDate { String era; String year; String month; String day; String hour; String minute; String second; String timezone; public void METSDate(String string) { String date; int timeAt = string.indexOf('T'); // if we've got a time signature, get it if (timeAt >= 0) { // get the date for later use date = string.substring(0, timeAt); // extract the time string String time = string.substring(timeAt+1); // check for time zone usage - currently '+' and '-' only... int zoneAt = time.indexOf('+'); if (zoneAt == -1) { zoneAt = time.indexOf('-'); } if (zoneAt >= 0) { this.timezone = time.substring(zoneAt); time = time.substring(0, zoneAt); } // finally, divide into hours, minutes etc. int hourAt = time.indexOf(':'); if (hourAt >= 0) { this.hour = time.substring(0, hourAt); time = time.substring(hourAt+1); int minuteAt = time.indexOf(':'); if (minuteAt >= 0) { this.minute = time.substring(0, minuteAt); this.second = time.substring(minuteAt+1); } else { this.minute = time; this.second = null; } } } else { this.timezone = null; this.hour = null; this.minute = null; this.second = null; date = string; } // get the era int prefixEnds = 0; while (!Character.isDigit(date.charAt(prefixEnds))) { prefixEnds ++; } if (prefixEnds != 0) { this.era = date.substring(0, prefixEnds); date = date.substring(prefixEnds); } else { this.era = null; } // finally, get the date // now try dividing up by '-' int yearAt = date.indexOf('-'); if (yearAt >= 0) { this.year = date.substring(0, yearAt); date = date.substring(yearAt+1); int monthAt = date.indexOf('-'); if (monthAt >= 0) { this.month = date.substring(0, monthAt); this.day = date.substring(monthAt+1); } else { this.month = date; this.day = null; } } else { // try dividing by YYYYMMDD - any part of which may be missing... if (date.length() >= 4) { this.year = date.substring(0, 4); if (date.length() >= 6) { this.month = date.substring(4, 6); this.day = date.substring(6); } else { this.month = date.substring(4); this.day = null; } } // we just have a day in this case... else { this.year = date; this.month = null; this.day = null; } } } public String toString() { if (this.year == null) { return ""; } StringBuffer buffer = new StringBuffer(); if (this.era != null) { buffer.append(era); } buffer.append(year); if (this.month != null) { buffer.append("-"); buffer.append(this.month); if (this.day != null) { buffer.append("-"); buffer.append(this.day); if (this.hour != null) { buffer.append("T"); buffer.append(this.hour); buffer.append(":"); buffer.append(this.minute); if (this.second != null) { buffer.append(":"); buffer.append(this.second); if (this.timezone != null) { buffer.append(this.timezone); } } } } } return buffer.toString(); } }