Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#setDay()
The following examples show how to use
javax.xml.datatype.XMLGregorianCalendar#setDay() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java From training with MIT License | 6 votes |
public static XMLGregorianCalendar extractXmlTime(Date timestamp) { if (timestamp == null) { return null; } XMLGregorianCalendar time = null; try { GregorianCalendar endCalendar = new GregorianCalendar(); endCalendar.setTime(timestamp); time = DatatypeFactory.newInstance().newXMLGregorianCalendar(endCalendar); time.setDay(DatatypeConstants.FIELD_UNDEFINED); time.setMonth(DatatypeConstants.FIELD_UNDEFINED); time.setYear(DatatypeConstants.FIELD_UNDEFINED); time.setTimezone(DatatypeConstants.FIELD_UNDEFINED); time.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); } catch (Exception e) { throw new RuntimeException(e); } return time; }
Example 2
Source File: DateUtils.java From training with MIT License | 6 votes |
public static XMLGregorianCalendar extractXmlTimeExact(String timestampString) { Date timestamp = parseDate(timestampString, EXACT_TIME_FORMAT); if (timestamp == null) { return null; } XMLGregorianCalendar time = null; try { GregorianCalendar endCalendar = new GregorianCalendar(); endCalendar.setTime(timestamp); time = DatatypeFactory.newInstance().newXMLGregorianCalendar(endCalendar); time.setDay(DatatypeConstants.FIELD_UNDEFINED); time.setMonth(DatatypeConstants.FIELD_UNDEFINED); time.setYear(DatatypeConstants.FIELD_UNDEFINED); time.setTimezone(DatatypeConstants.FIELD_UNDEFINED); time.normalize(); } catch (Exception e) { throw new RuntimeException(e); } return time; }
Example 3
Source File: PerfManagerMO.java From cloudstack with Apache License 2.0 | 6 votes |
/** * Converts Calendar object into XMLGregorianCalendar * * @param calendar Object to be converted * @return XMLGregorianCalendar */ private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) throws DatatypeConfigurationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar(); xgc.setYear(calendar.get(Calendar.YEAR)); xgc.setMonth(calendar.get(Calendar.MONTH) + 1); xgc.setDay(calendar.get(Calendar.DAY_OF_MONTH)); xgc.setHour(calendar.get(Calendar.HOUR_OF_DAY)); xgc.setMinute(calendar.get(Calendar.MINUTE)); xgc.setSecond(calendar.get(Calendar.SECOND)); xgc.setMillisecond(calendar.get(Calendar.MILLISECOND)); // Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds. int offsetInMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000); xgc.setTimezone(offsetInMinutes); return xgc; }
Example 4
Source File: AbstractNetSuiteTestBase.java From components with Apache License 2.0 | 6 votes |
protected static XMLGregorianCalendar composeDateTime() throws Exception { DateTime dateTime = DateTime.now(); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getRawOffset() / 60000); return xts; }
Example 5
Source File: XMLGregorianCalendarToDateTimeConverter.java From components with Apache License 2.0 | 5 votes |
@Override public XMLGregorianCalendar convertToDatum(Object timestamp) { if (timestamp == null) { return null; } long timestampMillis; if (timestamp instanceof Long) { timestampMillis = ((Long) timestamp).longValue(); } else if (timestamp instanceof Date) { timestampMillis = ((Date) timestamp).getTime(); } else { throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp); } MutableDateTime dateTime = new MutableDateTime(); dateTime.setMillis(timestampMillis); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
Example 6
Source File: CalendarUtilTest.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
private XMLGregorianCalendar addYears(int amount, XMLGregorianCalendar cal) { cal.setYear(2000); cal.setMonth(6); cal.setDay(1); cal.setHour(0); cal.setMinute(0); cal.setSecond(0); cal.setMillisecond(0); return calendarUtil.addYears(cal, amount); }
Example 7
Source File: XMLGregorianCalendarAsDateTime.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("deprecation") @Override public void createCalendar(Date date, XMLGregorianCalendar calendar) { calendar.setYear(date.getYear() + 1900); calendar.setMonth(date.getMonth() + 1); calendar.setDay(date.getDate()); calendar.setHour(date.getHours()); calendar.setMinute(date.getMinutes()); calendar.setSecond(date.getSeconds()); calendar.setMillisecond((int) (date.getTime() % 1000)); }
Example 8
Source File: CalendarUtilTest.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
/** * Test AddMonths into winterTime. * Result should be moths +2 and a one hour shift to the right. * */ @Test public void testAddMonthsIntoSummerTime() { XMLGregorianCalendar cal = calendarUtil.buildXMLGregorianCalendar(); cal.setMonth(2); cal.setDay(1); cal.setHour(0); cal.setMinute(0); cal.setSecond(0); cal.setMillisecond(0); XMLGregorianCalendar result = calendarUtil.addMonths(cal, 2); assertEquals(4, result.getMonth()); }
Example 9
Source File: CalendarUtilTest.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
private XMLGregorianCalendar addMonths(int amount, XMLGregorianCalendar cal) { cal.setMonth(6); cal.setDay(1); cal.setHour(0); cal.setMinute(0); cal.setSecond(0); cal.setMillisecond(0); return calendarUtil.addMonths(cal, amount); }
Example 10
Source File: XMLGregorianCalendarTest.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
public void testIt() { final XMLGregorianCalendar calendar = getDatatypeFactory() .newXMLGregorianCalendar(); calendar.setDay(15); calendar.setTimezone(120); final String gDayString = calendar.toXMLFormat(); logger.debug(gDayString); }
Example 11
Source File: ValueConverterTest.java From components with Apache License 2.0 | 5 votes |
@Test public void testXMLGregorianCalendarConverter() throws Exception { DateTimeZone tz1 = DateTimeZone.getDefault(); MutableDateTime dateTime1 = new MutableDateTime(tz1); dateTime1.setDate(System.currentTimeMillis()); Long controlValue1 = dateTime1.getMillis(); XMLGregorianCalendar xmlCalendar1 = datatypeFactory.newXMLGregorianCalendar(); xmlCalendar1.setYear(dateTime1.getYear()); xmlCalendar1.setMonth(dateTime1.getMonthOfYear()); xmlCalendar1.setDay(dateTime1.getDayOfMonth()); xmlCalendar1.setHour(dateTime1.getHourOfDay()); xmlCalendar1.setMinute(dateTime1.getMinuteOfHour()); xmlCalendar1.setSecond(dateTime1.getSecondOfMinute()); xmlCalendar1.setMillisecond(dateTime1.getMillisOfSecond()); xmlCalendar1.setTimezone(tz1.toTimeZone().getOffset(dateTime1.getMillis()) / 60000); FieldDesc fieldInfo = typeDesc.getField("tranDate"); NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName()); AvroConverter<XMLGregorianCalendar, Long> converter1 = (AvroConverter<XMLGregorianCalendar, Long>) transducer.getValueConverter(fieldInfo); assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema()); assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass()); assertEquals(controlValue1, converter1.convertToAvro(xmlCalendar1)); assertEquals(xmlCalendar1, converter1.convertToDatum(controlValue1)); AvroConverter<XMLGregorianCalendar, Object> converter2 = (AvroConverter<XMLGregorianCalendar, Object>) transducer.getValueConverter(fieldInfo); assertEquals(xmlCalendar1, converter2.convertToDatum(new Date(controlValue1.longValue()))); assertNull(converter1.convertToAvro(null)); }
Example 12
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
public XMLGregorianCalendar toXMLCalendar(Date d) throws Exception { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); XMLGregorianCalendar xml = DatatypeFactory.newInstance() .newXMLGregorianCalendar(); xml.setYear(gc.get(Calendar.YEAR)); xml.setMonth(gc.get(Calendar.MONTH) + 1); xml.setDay(gc.get(Calendar.DAY_OF_MONTH)); xml.setHour(gc.get(Calendar.HOUR_OF_DAY)); xml.setMinute(gc.get(Calendar.MINUTE)); xml.setSecond(gc.get(Calendar.SECOND)); return xml; }
Example 13
Source File: AbstractTypeTestClient.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testDateTime() throws Exception { if (!shouldRunTest("DateTime")) { return; } javax.xml.datatype.DatatypeFactory datatypeFactory = javax.xml.datatype.DatatypeFactory.newInstance(); XMLGregorianCalendar x = datatypeFactory.newXMLGregorianCalendar(); x.setYear(1975); x.setMonth(5); x.setDay(5); x.setHour(12); x.setMinute(30); x.setSecond(15); XMLGregorianCalendar yOrig = datatypeFactory.newXMLGregorianCalendar(); yOrig.setYear(2005); yOrig.setMonth(4); yOrig.setDay(1); yOrig.setHour(17); yOrig.setMinute(59); yOrig.setSecond(30); Holder<XMLGregorianCalendar> y = new Holder<>(yOrig); Holder<XMLGregorianCalendar> z = new Holder<>(); XMLGregorianCalendar ret; if (testDocLiteral) { ret = docClient.testDateTime(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testDateTime(x, y, z); } else { ret = rpcClient.testDateTime(x, y, z); } if (!perfTestOnly) { assertTrue("testDateTime(): Incorrect value for inout param", equalsDateTime(x, y.value)); assertTrue("testDateTime(): Incorrect value for out param", equalsDateTime(yOrig, z.value)); assertTrue("testDateTime(): Incorrect return value", equalsDateTime(x, ret)); } }
Example 14
Source File: SesameQueryTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testXmlCalendar() throws Exception { XMLGregorianCalendar xcal = data.newXMLGregorianCalendar(); xcal.setYear(2000); xcal.setMonth(11); xcal.setDay(6); ObjectQuery query = manager.prepareObjectQuery(SELECT_BY_DATE); query.setObject("date", xcal); List list = query.evaluate().asList(); assertEquals(3, list.size()); }
Example 15
Source File: SesameQueryTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testXmlCalendarZ() throws Exception { XMLGregorianCalendar xcal = data.newXMLGregorianCalendar(); xcal.setYear(2007); xcal.setMonth(11); xcal.setDay(6); xcal.setTimezone(OFFSET); ObjectQuery query = manager.prepareObjectQuery(SELECT_BY_DATE); query.setObject("date", xcal); List list = query.evaluate().asList(); assertEquals(7, list.size()); }
Example 16
Source File: CreateSubscriptionFromCustomerProfile.java From sample-code-java with MIT License | 4 votes |
public static ANetApiResponse run(String apiLoginId, String transactionKey, short intervalLength, Double amount, String profileId, String paymentProfileId, String customerAddressId) { //Common code to set for all requests ApiOperationBase.setEnvironment(Environment.SANDBOX); MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; merchantAuthenticationType.setName(apiLoginId); merchantAuthenticationType.setTransactionKey(transactionKey); ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); // Set up payment schedule PaymentScheduleType schedule = new PaymentScheduleType(); PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval(); interval.setLength(intervalLength); interval.setUnit(ARBSubscriptionUnitEnum.DAYS); schedule.setInterval(interval); try { XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(); startDate.setDay(30); startDate.setMonth(8); startDate.setYear(2020); schedule.setStartDate(startDate); //2020-08-30 } catch(Exception e) { } schedule.setTotalOccurrences((short)12); schedule.setTrialOccurrences((short)1); CustomerProfileIdType profile = new CustomerProfileIdType(); profile.setCustomerProfileId(profileId); profile.setCustomerPaymentProfileId(paymentProfileId); profile.setCustomerAddressId(customerAddressId); ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType(); arbSubscriptionType.setPaymentSchedule(schedule); arbSubscriptionType.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING)); arbSubscriptionType.setTrialAmount(new BigDecimal(0.0).setScale(2, RoundingMode.CEILING)); arbSubscriptionType.setProfile(profile); // Make the API Request ARBCreateSubscriptionRequest apiRequest = new ARBCreateSubscriptionRequest(); apiRequest.setSubscription(arbSubscriptionType); ARBCreateSubscriptionController controller = new ARBCreateSubscriptionController(apiRequest); controller.execute(); ARBCreateSubscriptionResponse response = controller.getApiResponse(); if (response!=null) { if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { System.out.println(response.getSubscriptionId()); System.out.println(response.getMessages().getMessage().get(0).getCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); } else { System.out.println("Failed to create Subscription: " + response.getMessages().getResultCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); } } return response; }
Example 17
Source File: CreateSubscription.java From sample-code-java with MIT License | 4 votes |
public static ANetApiResponse run(String apiLoginId, String transactionKey, short intervalLength, Double amount) { //Common code to set for all requests ApiOperationBase.setEnvironment(Environment.SANDBOX); MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; merchantAuthenticationType.setName(apiLoginId); merchantAuthenticationType.setTransactionKey(transactionKey); ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); // Set up payment schedule PaymentScheduleType schedule = new PaymentScheduleType(); PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval(); interval.setLength(intervalLength); interval.setUnit(ARBSubscriptionUnitEnum.DAYS); schedule.setInterval(interval); try { XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(); startDate.setDay(30); startDate.setMonth(8); startDate.setYear(2020); schedule.setStartDate(startDate); //2020-08-30 } catch(Exception e) { } schedule.setTotalOccurrences((short)12); schedule.setTrialOccurrences((short)1); // Populate the payment data PaymentType paymentType = new PaymentType(); CreditCardType creditCard = new CreditCardType(); creditCard.setCardNumber("4111111111111111"); creditCard.setExpirationDate("1220"); paymentType.setCreditCard(creditCard); ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType(); arbSubscriptionType.setPaymentSchedule(schedule); arbSubscriptionType.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING)); arbSubscriptionType.setTrialAmount(new BigDecimal(1.23).setScale(2, RoundingMode.CEILING)); arbSubscriptionType.setPayment(paymentType); NameAndAddressType name = new NameAndAddressType(); name.setFirstName("John"); name.setLastName("Smith"); arbSubscriptionType.setBillTo(name); // Make the API Request ARBCreateSubscriptionRequest apiRequest = new ARBCreateSubscriptionRequest(); apiRequest.setSubscription(arbSubscriptionType); ARBCreateSubscriptionController controller = new ARBCreateSubscriptionController(apiRequest); controller.execute(); ARBCreateSubscriptionResponse response = controller.getApiResponse(); if (response!=null) { if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { System.out.println(response.getSubscriptionId()); System.out.println(response.getMessages().getMessage().get(0).getCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); } else { System.out.println("Failed to create Subscription: " + response.getMessages().getResultCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); } } return response; }
Example 18
Source File: AbstractTypeTestClient.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testDate() throws Exception { if (!shouldRunTest("Date")) { return; } javax.xml.datatype.DatatypeFactory datatypeFactory = javax.xml.datatype.DatatypeFactory.newInstance(); XMLGregorianCalendar x = datatypeFactory.newXMLGregorianCalendar(); x.setYear(1975); x.setMonth(5); x.setDay(5); XMLGregorianCalendar yOrig = datatypeFactory.newXMLGregorianCalendar(); yOrig.setYear(2004); yOrig.setMonth(4); yOrig.setDay(1); Holder<XMLGregorianCalendar> y = new Holder<>(yOrig); Holder<XMLGregorianCalendar> z = new Holder<>(); XMLGregorianCalendar ret; if (testDocLiteral) { ret = docClient.testDate(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testDate(x, y, z); } else { ret = rpcClient.testDate(x, y, z); } if (!perfTestOnly) { assertTrue("testDate(): Incorrect value for inout param " + x + " != " + y.value, equalsDate(x, y.value)); assertTrue("testDate(): Incorrect value for out param", equalsDate(yOrig, z.value)); assertTrue("testDate(): Incorrect return value", equalsDate(x, ret)); } x = datatypeFactory.newXMLGregorianCalendar(); yOrig = datatypeFactory.newXMLGregorianCalendar(); y = new Holder<>(yOrig); z = new Holder<>(); try { if (testDocLiteral) { ret = docClient.testDate(x, y, z); } else { ret = rpcClient.testDate(x, y, z); } fail("Expected to catch WebServiceException when calling" + " testDate() with uninitialized parameters."); } catch (RuntimeException re) { assertNotNull(re); } }
Example 19
Source File: XMLGregorianCalendarAsGMonthDay.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("deprecation") @Override public void createCalendar(Date date, XMLGregorianCalendar calendar) { calendar.setMonth(date.getMonth() + 1); calendar.setDay(date.getDate()); }
Example 20
Source File: ParseDate.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Value evaluate(ValueFactory valueFactory, Value arg1, Value arg2) throws ValueExprEvaluationException { if (!(arg1 instanceof Literal) || !(arg2 instanceof Literal)) { throw new ValueExprEvaluationException("Both arguments must be literals"); } Literal value = (Literal) arg1; Literal format = (Literal) arg2; FieldAwareGregorianCalendar cal = new FieldAwareGregorianCalendar(); SimpleDateFormat formatter = new SimpleDateFormat(format.getLabel()); formatter.setCalendar(cal); try { formatter.parse(value.getLabel()); } catch (ParseException e) { throw new ValueExprEvaluationException(e); } XMLGregorianCalendar xmlCal = datatypeFactory.newXMLGregorianCalendar(cal); if (!cal.isDateSet()) { xmlCal.setYear(DatatypeConstants.FIELD_UNDEFINED); xmlCal.setMonth(DatatypeConstants.FIELD_UNDEFINED); xmlCal.setDay(DatatypeConstants.FIELD_UNDEFINED); } if (!cal.isTimeSet()) { xmlCal.setHour(DatatypeConstants.FIELD_UNDEFINED); xmlCal.setMinute(DatatypeConstants.FIELD_UNDEFINED); xmlCal.setSecond(DatatypeConstants.FIELD_UNDEFINED); } if (!cal.isMillisecondSet()) { xmlCal.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); } String dateValue = xmlCal.toXMLFormat(); QName dateType = xmlCal.getXMLSchemaType(); if (!cal.isTimezoneSet()) { int len = dateValue.length(); if (dateValue.endsWith("Z")) { dateValue = dateValue.substring(0, len - 1); } else if (dateValue.charAt(len - 6) == '+' || dateValue.charAt(len - 6) == '-') { dateValue = dateValue.substring(0, len - 6); } } return valueFactory.createLiteral(dateValue, XMLDatatypeUtil.qnameToURI(dateType)); }