Check GeneralizedTime has minutes and seconds and apply different patterns
@@ -277,10 +277,18 @@ public Date getDate()
{
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
}
- else
+ else if (hasSeconds())
{
dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
}
+ else if (hasMinutes())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmm'Z'");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHH'Z'");
+ }
dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
}
@@ -291,10 +299,18 @@ else if (stime.indexOf('-') > 0 || stime.indexOf('+') > 0)
{
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSz");
}
- else
+ else if (hasSeconds())
{
dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
}
+ else if (hasMinutes())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmz");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHz");
+ }
dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
}
@@ -304,10 +320,18 @@ else if (stime.indexOf('-') > 0 || stime.indexOf('+') > 0)
{
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
}
- else
+ else if (hasSeconds())
{
dateF = new SimpleDateFormat("yyyyMMddHHmmss");
}
+ else if (hasMinutes())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmm");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHH");
+ }
dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
}
@@ -361,6 +385,16 @@ private boolean hasFractionalSeconds()
return false;
}
+ private boolean hasSeconds()
+ {
+ return time.length >= 14 && time[12] >= '0' && time[12] <= '9' && time[13] >= '0' && time[13] <= '9';
+ }
+
+ private boolean hasMinutes()
+ {
+ return time.length >= 12 && time[10] >= '0' && time[10] <= '9' && time[11] >= '0' && time[11] <= '9';
+ }
+
boolean isConstructed()
{
return false;
