Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#setMonth()
The following examples show how to use
javax.xml.datatype.XMLGregorianCalendar#setMonth() .
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 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 2
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 3
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 4
Source File: JavaxTypesTest.java From jackson-modules-base with Apache License 2.0 | 5 votes |
public void testGregorianCalendar() throws Exception { DatatypeFactory f = DatatypeFactory.newInstance(); XMLGregorianCalendar in = f.newXMLGregorianCalendar(); in.setYear(2014); in.setMonth(3); String json = MAPPER.writeValueAsString(in); assertNotNull(json); XMLGregorianCalendar out = MAPPER.readValue(json, XMLGregorianCalendar.class); assertNotNull(out); // minor sanity check assertEquals(in.getYear(), out.getYear()); }
Example 5
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 6
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 left. * */ @Test public void testAddMonthsIntoWinterTime() { XMLGregorianCalendar cal = calendarUtil.buildXMLGregorianCalendar(); cal.setMonth(10); cal.setDay(1); cal.setHour(0); cal.setMinute(0); cal.setSecond(0); cal.setMillisecond(0); XMLGregorianCalendar result = calendarUtil.addMonths(cal, 2); assertEquals(12, result.getMonth()); }
Example 7
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 8
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 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: 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 11
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 12
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 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: 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 15
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 16
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 17
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 18
Source File: XMLGregorianCalendarAsGMonth.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); }
Example 19
Source File: AbstractXMLGregorianCalendarAdapter.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public void setMonth(Calendar source, XMLGregorianCalendar target) { target.setMonth(source.get(Calendar.MONTH) + 1); }
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)); }