@Override public byte[] toBytes(Date d) { return VR.str2bytes(DateUtils.formatDT(d), null); }
public static Date parseDA(String s, boolean end) { if (s == null || s.length() == 0) return null; Calendar c = new GregorianCalendar(); c.clear(); if (end) { setToDec31(c); } parseDA(c, s, 0, s.length()); return c.getTime(); }
public static Date parseDT(String s, boolean end) { if (s == null || s.length() == 0) { return null; } Calendar c = new GregorianCalendar(); c.clear(); if (end) { setToDec31(c); setTo2359(c); } int len = s.length(); if (len >= 5) { final char tzsign = s.charAt(len - 5); if (tzsign == '+' || tzsign == '-') { len -= 5; c.setTimeZone(TimeZone.getTimeZone("GMT" + s.substring(len))); } } int pos = parseDA(c, s, 0, len); if (pos + 2 <= len) { parseTM(c, s, pos, len); } return c.getTime(); }
/** * Parses a value that has a TM VR as a {@link Date}. * * @param s the TM string to parse. * @param end whether or not to initialize missing precision to the maximum values (December * 31st, 23:59). * @return the parsed date or <code>null</code> if the input is empty. */ public static Date parseTM(String s, boolean end) { if (s == null || s.length() == 0) { return null; } Calendar c = new GregorianCalendar(); c.clear(); if (end) { setTo2359(c); } parseTM(c, s, 0, s.length()); return c.getTime(); }
@Override public byte[] toBytes(Date d) { return VR.str2bytes(DateUtils.formatDA(d), null); }
@Override public byte[] toBytes(Date d) { return VR.str2bytes(DateUtils.formatTM(d), null); }
@Override public Date toDate(byte[] val) { return DateUtils.parseDA( StringUtils.trim(VR.bytes2str1(val, null)), false); }
public Date[] getDates(int daTag, int tmTag, Date[] defVal) { Date[] da = getDates(daTag, VR.DA); Date[] tm = getDates(tmTag, VR.TM); if (da == null) return defVal; if (tm != null) { for (int i = 0, n = Math.min(da.length, tm.length); i < n; ++i) { da[i] = DateUtils.toDateTime(da[i], tm[i]); } } return da; }
@Override public Date toDate(byte[] val) { return DateUtils.parseDT( StringUtils.trim(VR.bytes2str1(val, null)), false); }
@Override public Date toDate(byte[] val) { return DateUtils.parseTM( StringUtils.trim(VR.bytes2str1(val, null)), false); }
private static void setToDec31(Calendar c) { c.set(Calendar.MONTH, 11); c.set(Calendar.DAY_OF_MONTH, 31); setTo2359(c); }
int millis = roundMicrosToMillis(micros); c.set(Calendar.MILLISECOND, millis);
@Override public byte[] toBytes(Date[] d) { if (d == null || d.length == 0) return null; String[] ss = new String[d.length]; for (int i = 0; i < ss.length; i++) { ss[i] = DateUtils.formatDA(d[i]); } return VR.strs2bytes(ss, null); }
@Override public byte[] toBytes(Date[] d) { if (d == null || d.length == 0) return null; String[] ss = new String[d.length]; for (int i = 0; i < ss.length; i++) { ss[i] = DateUtils.formatTM(d[i]); } return VR.strs2bytes(ss, null); }
@Override public Date[] toDates(byte[] val) { if (val == null || val.length == 0) return EMPTY_DATE_ARRAY; String[] ss = StringUtils.trim(VR.bytes2strs(val, null)); Date[] ds = new Date[ss.length]; for (int i = 0; i < ds.length; i++) { ds[i] = DateUtils.parseDA(ss[i], false); } return ds; }
public Date getDate(int daTag, int tmTag, Date defVal) { Date da = getDate(daTag, VR.DA); return da == null ? defVal : DateUtils.toDateTime(da, getDate(tmTag, VR.TM)); }
@Override public Date[] toDates(byte[] val) { if (val == null || val.length == 0) return EMPTY_DATE_ARRAY; String[] ss = StringUtils.trim(VR.bytes2strs(val, null)); Date[] ds = new Date[ss.length]; for (int i = 0; i < ds.length; i++) { ds[i] = DateUtils.parseDT(ss[i], false); } return ds; }
@Override public Date[] toDates(byte[] val) { if (val == null || val.length == 0) return EMPTY_DATE_ARRAY; String[] ss = StringUtils.trim(VR.bytes2strs(val, null)); Date[] ds = new Date[ss.length]; for (int i = 0; i < ds.length; i++) { ds[i] = DateUtils.parseTM(ss[i], false); } return ds; }
public static String formatDA(Date d) { if (d == null) return null; Calendar c = new GregorianCalendar(); c.setTime(d); return formatDA(c, new StringBuffer(8)).toString(); }