Refine search
StringBuilder buf = new StringBuilder(); if (getSign() < 0) { buf.append('-'); BigInteger years = (BigInteger) getField(DatatypeConstants.YEARS); if (years != null) { buf.append(years).append('Y'); BigInteger months = (BigInteger) getField(DatatypeConstants.MONTHS); if (months != null) { buf.append(months).append('M'); BigInteger days = (BigInteger) getField(DatatypeConstants.DAYS); if (days != null) { buf.append(days).append('D'); BigInteger hours = (BigInteger) getField(DatatypeConstants.HOURS); BigInteger minutes = (BigInteger) getField(DatatypeConstants.MINUTES); BigDecimal seconds = (BigDecimal) getField(DatatypeConstants.SECONDS); if (hours != null || minutes != null || seconds != null) { buf.append('T'); buf.append(toString(seconds)).append('S');
cal.setTime(startInstant); this.addTo(cal); return getCalendarTimeInMillis(cal) - startInstant.getTime();
protected Calendar add(Calendar date, Duration duration) { Calendar calendar = (Calendar) date.clone(); // duration.addTo does not account for daylight saving time (xerces), // reversing order of addition fixes the problem calendar.add(Calendar.SECOND, duration.getSeconds() * duration.getSign()); calendar.add(Calendar.MINUTE, duration.getMinutes() * duration.getSign()); calendar.add(Calendar.HOUR, duration.getHours() * duration.getSign()); calendar.add(Calendar.DAY_OF_MONTH, duration.getDays() * duration.getSign()); calendar.add(Calendar.MONTH, duration.getMonths() * duration.getSign()); calendar.add(Calendar.YEAR, duration.getYears() * duration.getSign()); return calendar; }
Calendar cal = (Calendar) startInstant.clone(); addTo(cal); return getCalendarTimeInMillis(cal) - getCalendarTimeInMillis(startInstant);
public static void main(String arg[]) throws Exception { DatatypeFactory factory = DatatypeFactory.newInstance(); Duration d = factory.newDuration("P3D"); long secs1 = d.getTimeInMillis(new Date()) / 1000; Calendar c = Calendar.getInstance(); c.set(1970, 0, 1, 0, 0, 0); long secs2 = d.getTimeInMillis(c.getTime()) / 1000; System.out.printf("%d %d same = %s%n", secs1, secs2, secs1 == secs2); } }
private void resetByDuration(Consumer<byte[], byte[]> client, Set<TopicPartition> inputTopicPartitions, Duration duration) throws DatatypeConfigurationException { final Date now = new Date(); duration.negate().addTo(now); final long timestamp = now.getTime(); final Map<TopicPartition, Long> topicPartitionsAndTimes = new HashMap<>(inputTopicPartitions.size()); for (final TopicPartition topicPartition : inputTopicPartitions) { topicPartitionsAndTimes.put(topicPartition, timestamp); } final Map<TopicPartition, OffsetAndTimestamp> topicPartitionsAndOffset = client.offsetsForTimes(topicPartitionsAndTimes); for (final TopicPartition topicPartition : inputTopicPartitions) { client.seek(topicPartition, topicPartitionsAndOffset.get(topicPartition).offset()); } }
public void setExpires(Expires ex) { Duration d = null; expires = null; if (null != ex) { d = ex.getValue(); } if (null != d && !d.equals(DatatypeFactory.PT0S)) { Date now = new Date(); expires = new Date(now.getTime() + ex.getValue().getTimeInMillis(now)); } }
public Object fromString(String str) { Duration d = _factory.newDuration(str); long start = System.currentTimeMillis(); Date asDate = new Date(start); d.addTo(asDate); return new Long(asDate.getTime() - start); }
return null; if(!nv1.isDateTime() && !nv1.isDate() && !nv1.isTime()) throw new ExprEvalException("Not a valid date, datetime or time:"+nv1); Duration tzDuration = nv2.getDuration(); tzOffset = tzDuration.getSign()*(tzDuration.getMinutes() + 60*tzDuration.getHours()); if(tzDuration.getSeconds() > 0) throw new ExprEvalException("The timezone duration should be an integral number of minutes"); int absTzOffset = java.lang.Math.abs(tzOffset); tzOffset = TimeZone.getDefault().getOffset(new Date().getTime())/(1000*60); Duration durToAdd = NodeValue.xmlDatatypeFactory.newDurationDayTime((tzOffset-inputOffset) > 0,0,0,java.lang.Math.abs(tzOffset-inputOffset),0); if(hasTz) calValue.add(durToAdd);
cal.setTime(date); this.addTo(cal); date.setTime(getCalendarTimeInMillis(cal));
private ResultSequence minusXSTimeDuration(Item at) { XSTime val = (XSTime) at; Duration dtduration = null; Calendar thisCal = normalizeCalendar(calendar(), tz()); Calendar thatCal = normalizeCalendar(val.calendar(), val.tz()); long duration = thisCal.getTimeInMillis() - thatCal.getTimeInMillis(); dtduration = _datatypeFactory.newDuration(duration); return ResultSequenceFactory.create_new(XSDayTimeDuration.parseDTDuration(dtduration.toString())); }
private Date getDateAfterRepeat(Date date) { if (start != null) { Date cur = start; for (int i=0;i<times && !cur.after(date);i++) { cur = add(cur, period); } return cur.before(date) ? null : cur; } Date cur = add(end, period.negate()); Date next = end; for (int i=0;i<times && cur.after(date);i++) { next = cur; cur = add(cur, period.negate()); } return next.before(date) ? null : next; }
private Duration createDuration(Calendar when, long now) throws Exception { long seconds = (now - when.getTimeInMillis()) / 1000; return DatatypeFactory.newInstance().newDuration("PT" + seconds + "S").negate(); }
@Override public void serialize(Duration value, JsonGenerator jgen, SerializerProvider provider) throws IOException { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(0); jgen.writeNumber(value.getTimeInMillis(cal)); } }
public static ExpirationType toExpirationTypeContainingDuration(XMLGregorianCalendar date) { ExpirationType et = new ExpirationType(); XMLGregorianCalendar now = factory.newXMLGregorianCalendar(new GregorianCalendar()); XMLGregorianCalendar then = factory.newXMLGregorianCalendar(date.toGregorianCalendar()); long durationMillis = then.toGregorianCalendar().getTimeInMillis() - now.toGregorianCalendar().getTimeInMillis(); Duration duration = factory.newDuration(durationMillis); et.setValue(duration.toString()); return et; }
// parsing String iso = "P2Y4M30DT17H5M57.123S"; javax.xml.datatype.Duration xmlDuration = DatatypeFactory.newInstance().newDuration(iso); int years = xmlDuration.getYears(); int months = xmlDuration.getMonths(); int days = xmlDuration.getDays(); int hours = xmlDuration.getHours(); int minutes = xmlDuration.getMinutes(); int fullSeconds = xmlDuration.getSeconds(); BigDecimal seconds = (BigDecimal) xmlDuration.getField(DatatypeConstants.SECONDS); // generating ISO-string String xml = xmlDuration.toString(); System.out.println(xml); // P2Y4M30DT17H5M57.123S
dur = DatatypeFactory.newInstance().newDuration(str); seconds = dur.getTimeInMillis(STATIC_DATE) / 1000; } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex);