Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#setYear()
The following examples show how to use
javax.xml.datatype.XMLGregorianCalendar#setYear() .
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: SesameQueryTest.java From anno4j with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { module = new ObjectRepositoryConfig(); module.addConcept(Concept.class); super.setUp(); ObjectRepository factory = (ObjectRepository) repository; manager = factory.getConnection(); data = DatatypeFactory.newInstance(); for (int i=1;i<5;i++) { Class<?>[] concepts = {}; Concept concept = manager.addDesignation(manager.getObject(NS + "concept" + i), Concept.class); XMLGregorianCalendar xcal = data.newXMLGregorianCalendar(); xcal.setYear(2000); xcal.setMonth(11); xcal.setDay(i*2); concept.setDate(xcal); Class<?>[] concepts1 = {}; concept = manager.addDesignation(manager.getObject(NS + "conceptZ" + i), Concept.class); xcal = data.newXMLGregorianCalendar(); xcal.setYear(2007); xcal.setMonth(11); xcal.setDay(i*2); xcal.setTimezone(OFFSET); concept.setDate(xcal); } }
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: XMLGregorianCalendarTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "gMonth") public void checkIsValid(String month) { XMLGregorianCalendar gMonth = datatypeFactory.newXMLGregorianCalendar(month); gMonth.setYear(null); Assert.assertTrue(gMonth.isValid(), gMonth.toString() + " should isValid"); }
Example 6
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 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: FATCAMetadata.java From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal | 5 votes |
protected XMLGregorianCalendar genTaxYear(int year) { XMLGregorianCalendar taxyear = new XMLGregorianCalendarImpl(new GregorianCalendar()); taxyear.setTimezone(DatatypeConstants.FIELD_UNDEFINED); taxyear.setTime(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); taxyear.setDay(DatatypeConstants.FIELD_UNDEFINED); taxyear.setMonth(DatatypeConstants.FIELD_UNDEFINED); taxyear.setYear(year); return taxyear; }
Example 9
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 10
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 11
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 12
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 13
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 14
Source File: XMLGregorianCalendarAsGYear.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("deprecation") @Override public void createCalendar(Date date, XMLGregorianCalendar calendar) { calendar.setYear(date.getYear() + 1900); }
Example 15
Source File: XMLGregorianCalendarAsGYearMonth.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("deprecation") @Override public void createCalendar(Date date, XMLGregorianCalendar calendar) { calendar.setYear(date.getYear() + 1900); calendar.setMonth(date.getMonth() + 1); }
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: 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)); }
Example 20
Source File: XMLGregorianCalendarTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
@Test public void checkToGregorianCalendar01() { XMLGregorianCalendar time_16_17_18 = datatypeFactory.newXMLGregorianCalendar("16:17:18"); XMLGregorianCalendar date_2001_02_03 = datatypeFactory.newXMLGregorianCalendar("2001-02-03"); GregorianCalendar calendar = date_2001_02_03.toGregorianCalendar(null, null, time_16_17_18); int year = calendar.get(YEAR); int minute = calendar.get(MINUTE); assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute); calendar = time_16_17_18.toGregorianCalendar(null, null, date_2001_02_03); year = calendar.get(YEAR); minute = calendar.get(MINUTE); assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute); date_2001_02_03.setMinute(3); date_2001_02_03.setYear(null); XMLGregorianCalendar date_time = datatypeFactory.newXMLGregorianCalendar("2003-04-11T02:13:01Z"); calendar = date_2001_02_03.toGregorianCalendar(null, null, date_time); year = calendar.get(YEAR); minute = calendar.get(MINUTE); int hour = calendar.get(HOUR); assertTrue((year == 2003 && hour == 2 && minute == 3), " expecting year == 2003, hour == 2, minute == 3" + ", result is year == " + year + ", hour == " + hour + ", minute == " + minute); }