*/
public String toFinestUntil(String until)
throws BadArgumentException {
if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) {
if (!isValidGranularity(until))
throw new BadArgumentException();
return until;
}
if (until.length() > VALID_GRANULARITIES[supportedGranularityOffset].length()) {
throw new BadArgumentException();
}
StringBuffer sb = new StringBuffer(until);
if (sb.charAt(sb.length()-1) == 'Z')
sb.setLength(sb.length()-1);
if (sb.length() < VALID_GRANULARITIES[0].length()) {
while (sb.length() < 4) sb.append("9");
switch (sb.length()) {
case 4: // YYYY
sb.append("-");
case 5: // YYYY-
sb.append("12");
case 7: // YYYY-MM
sb.append("-");
case 8: // YYYY-MM-
sb.append("31");
break;
case 6: // YYYY-M
case 9: // YYYY-MM-D
throw new BadArgumentException();
}
}
until = sb.toString();
if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) {
if (!isValidGranularity(until))
throw new BadArgumentException();
return until;
}
if (sb.length() < VALID_GRANULARITIES[1].length()) {
switch (sb.length()) {
case 10: // YYYY-MM-DD
sb.append("T");
case 11: // YYYY-MM-DDT
sb.append("23");
case 13: // YYYY-MM-DDThh
sb.append(":");
case 14: // YYYY-MM-DDThh:
sb.append("59");
// case 16: // YYYY-MM-DDThh:mm
// sb.append("Z");
// break;
// case 12: // YYYY-MM-DDTh
// case 15: // YYYY-MM-DDThh:m
// throw new BadGranularityException();
// }
// }
// until = sb.toString();
// if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) {
// if (!isValidGranularity(until))
// throw new BadGranularityException();
// return until;
// }
// if (sb.charAt(sb.length()-1) == 'Z')
// sb.setLength(sb.length()-1); // remove the trailing 'Z'
// if (sb.length() < VALID_GRANULARITIES[2].length()) {
// switch (sb.length()) {
case 16: // YYYY-MM-DDThh:mm
sb.append(":");
case 17: // YYYY-MM-DDThh:mm:
sb.append("59");
case 19: // YYYY-MM-DDThh:mm:ss
sb.append("Z");
break;
case 18: // YYYY-MM-DDThh:mm:s
throw new BadArgumentException();
}
}
// until = sb.toString();
// if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) {
// if (!isValidGranularity(until))
// throw new BadGranularityException();
// return until;
// }
// if (sb.charAt(sb.length()-1) == 'Z')
// sb.setLength(sb.length()-1); // remove the trailing 'Z'
// switch (sb.length()) {
// case 19: // YYYY-MM-DDThh:mm:ss
// sb.append(".");
// case 20: // YYYY-MM-DDThh:mm:ss.
// sb.append("0");
// case 21: // YYYY-MM-DDThh:mm:ss.s
// sb.append("Z");
// break;
// }
until = sb.toString();
if (!isValidGranularity(until))
throw new BadArgumentException();
return until;
}