use of javax.xml.datatype.Duration in project apache-kafka-on-k8s by banzaicloud.
the class StreamsResetter method maybeReset.
private void maybeReset(final String groupId, final Consumer<byte[], byte[]> client, final Set<TopicPartition> inputTopicPartitions) throws Exception {
if (inputTopicPartitions.size() > 0) {
System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")");
if (options.has(toOffsetOption)) {
resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption));
} else if (options.has(toEarliestOption)) {
client.seekToBeginning(inputTopicPartitions);
} else if (options.has(toLatestOption)) {
client.seekToEnd(inputTopicPartitions);
} else if (options.has(shiftByOption)) {
shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption));
} else if (options.has(toDatetimeOption)) {
final String ts = options.valueOf(toDatetimeOption);
final long timestamp = getDateTime(ts);
resetToDatetime(client, inputTopicPartitions, timestamp);
} else if (options.has(byDurationOption)) {
final String duration = options.valueOf(byDurationOption);
final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration);
resetByDuration(client, inputTopicPartitions, durationParsed);
} else if (options.has(fromFileOption)) {
final String resetPlanPath = options.valueOf(fromFileOption);
final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath);
resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset);
} else {
client.seekToBeginning(inputTopicPartitions);
}
for (final TopicPartition p : inputTopicPartitions) {
System.out.println("Topic: " + p.topic() + " Partition: " + p.partition() + " Offset: " + client.position(p));
}
}
}
use of javax.xml.datatype.Duration in project msgraph-sdk-java by microsoftgraph.
the class OutlookTests method testGetFindMeetingTimes.
@Test
public void testGetFindMeetingTimes() {
TestBase testBase = new TestBase();
// Get the first user in the tenant
User me = testBase.graphClient.me().buildRequest().get();
IUserCollectionPage users = testBase.graphClient.users().buildRequest().get();
User tenantUser = users.getCurrentPage().get(0);
// Ensure that the user grabbed is not the logged-in user
if (tenantUser.mail.equals(me.mail)) {
tenantUser = users.getCurrentPage().get(1);
}
ArrayList<AttendeeBase> attendees = new ArrayList<AttendeeBase>();
AttendeeBase attendeeBase = new AttendeeBase();
EmailAddress email = new EmailAddress();
email.address = tenantUser.mail;
attendeeBase.emailAddress = email;
attendees.add(attendeeBase);
try {
DatatypeFactory.newInstance().newDuration("PT30M");
Duration duration = DatatypeFactory.newInstance().newDuration("PT30M");
MeetingTimeSuggestionsResult result = testBase.graphClient.me().findMeetingTimes(attendees, null, null, duration, 10, true, false, 10.0).buildRequest().post();
assertNotNull(result);
} catch (Exception e) {
Assert.fail("Duration could not be created from String");
}
}
use of javax.xml.datatype.Duration in project rdf4j by eclipse.
the class LiteralsTest method testGetDurationValueLiteralDuration.
@Test
public final void testGetDurationValueLiteralDuration() throws Exception {
DatatypeFactory dtFactory = DatatypeFactory.newInstance();
Duration fallback = dtFactory.newDuration(true, 1, 1, 1, 1, 1, 1);
Duration result = Literals.getDurationValue(vf.createLiteral("P5Y"), fallback);
assertNotNull(result);
assertFalse(result.equals(fallback));
assertEquals(5, result.getYears());
}
use of javax.xml.datatype.Duration in project webtools.sourceediting by eclipse.
the class FnAdjustTimeToTimeZone method adjustTime.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence adjustTime(Collection args, DynamicContext dc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expectedArgs());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
ResultSequence arg2 = ResultBuffer.EMPTY;
if (argiter.hasNext()) {
arg2 = (ResultSequence) argiter.next();
}
XSTime time = (XSTime) arg1.first();
XSDayTimeDuration timezone = null;
if (arg2.empty()) {
if (time.timezoned()) {
XSTime localized = new XSTime(time.calendar(), null);
return localized;
} else {
return arg1;
}
}
XMLGregorianCalendar xmlCalendar = null;
if (time.tz() != null) {
xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
} else {
xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
}
timezone = (XSDayTimeDuration) arg2.first();
if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
throw DynamicError.invalidTimezone();
}
if (time.tz() == null) {
return new XSTime(time.calendar(), timezone);
}
Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
xmlCalendar.add(duration);
return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
use of javax.xml.datatype.Duration in project webtools.sourceediting by eclipse.
the class FnAdjustDateToTimeZone method adjustDate.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence adjustDate(Collection args, DynamicContext dc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expectedArgs());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
ResultSequence arg2 = ResultBuffer.EMPTY;
if (argiter.hasNext()) {
arg2 = (ResultSequence) argiter.next();
}
XSDate date = (XSDate) arg1.item(0);
XSDayTimeDuration timezone = null;
if (arg2.empty()) {
if (date.timezoned()) {
XSDate localized = new XSDate(date.calendar(), null);
return localized;
}
return arg1;
}
timezone = (XSDayTimeDuration) arg2.item(0);
if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
throw DynamicError.invalidTimezone();
}
if (date.tz() == null) {
return new XSDate(date.calendar(), timezone);
}
XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date.normalizeCalendar(date.calendar(), date.tz()));
Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
xmlCalendar.add(duration);
return new XSDate(xmlCalendar.toGregorianCalendar(), timezone);
}
Aggregations