List of usage examples for org.joda.time DateTime toDateTimeISO
public DateTime toDateTimeISO()
this
if possible. From source file:com.github.thorqin.toolkit.utility.StringUtils.java
public static String toISO8601(DateTime dateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); return dateTime.toDateTimeISO().toString(formatter); }
From source file:com.ning.billing.jaxrs.KillbillClient.java
License:Apache License
protected void adjustInvoiceItem(final String accountId, final String invoiceId, final String invoiceItemId, @Nullable final DateTime requestedDate, @Nullable final BigDecimal amount, @Nullable final Currency currency) throws IOException { final String uri = JaxrsResource.INVOICES_PATH + "/" + invoiceId; final Map<String, String> queryParams = new HashMap<String, String>(); if (requestedDate != null) { queryParams.put(JaxrsResource.QUERY_REQUESTED_DT, requestedDate.toDateTimeISO().toString()); }/*from ww w . j a v a2s . com*/ final InvoiceItemJsonSimple adjustment = new InvoiceItemJsonSimple(invoiceItemId, null, null, accountId, null, null, null, null, null, null, null, amount, currency, null); final String adjustmentJson = mapper.writeValueAsString(adjustment); final Response response = doPost(uri, adjustmentJson, queryParams, DEFAULT_HTTP_TIMEOUT_SEC); Assert.assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode()); }
From source file:com.ning.billing.jaxrs.KillbillClient.java
License:Apache License
private InvoiceJsonWithItems doCreateExternalCharge(final String accountId, @Nullable final String invoiceId, @Nullable final String bundleId, @Nullable final BigDecimal amount, @Nullable final Currency currency, final DateTime requestedDate, final String uri) throws IOException { final Map<String, String> queryParams = new HashMap<String, String>(); if (requestedDate != null) { queryParams.put(JaxrsResource.QUERY_REQUESTED_DT, requestedDate.toDateTimeISO().toString()); }/*from w w w . j av a 2s . c o m*/ final InvoiceItemJsonSimple externalCharge = new InvoiceItemJsonSimple(null, invoiceId, null, accountId, bundleId, null, null, null, null, null, null, amount, currency, null); final String externalChargeJson = mapper.writeValueAsString(externalCharge); final Response response = doPost(uri, externalChargeJson, queryParams, DEFAULT_HTTP_TIMEOUT_SEC); Assert.assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode()); final String location = response.getHeader("Location"); Assert.assertNotNull(location); final Map<String, String> queryParamsForInvoice = new HashMap<String, String>(); queryParamsForInvoice.put(JaxrsResource.QUERY_ACCOUNT_ID, accountId); queryParamsForInvoice.put(JaxrsResource.QUERY_INVOICE_WITH_ITEMS, "true"); final Response invoiceResponse = doGetWithUrl(location, queryParamsForInvoice, DEFAULT_HTTP_TIMEOUT_SEC); assertEquals(invoiceResponse.getStatusCode(), Status.OK.getStatusCode()); final String invoicesBaseJson = invoiceResponse.getResponseBody(); final InvoiceJsonWithItems invoice = mapper.readValue(invoicesBaseJson, new TypeReference<InvoiceJsonWithItems>() { }); assertNotNull(invoice); return invoice; }
From source file:com.ning.billing.junction.plumbing.billing.BillCycleDayCalculator.java
License:Apache License
@VisibleForTesting int calculateBcdFromSubscription(final Subscription subscription, final Plan plan, final Account account, final Catalog catalog, final InternalCallContext context) throws AccountApiException, CatalogApiException { // Retrieve the initial phase type for that subscription // TODO - this should be extracted somewhere, along with this code above final PhaseType initialPhaseType; final List<EffectiveSubscriptionInternalEvent> transitions = entitlementApi.getAllTransitions(subscription, context);//from w w w . ja v a 2s . c o m if (transitions.size() == 0) { initialPhaseType = null; } else { final DateTime requestedDate = subscription.getStartDate(); final String initialPhaseString = transitions.get(0).getNextPhase(); if (initialPhaseString == null) { initialPhaseType = null; } else { final PlanPhase initialPhase = catalog.findPhase(initialPhaseString, requestedDate, subscription.getStartDate()); if (initialPhase == null) { initialPhaseType = null; } else { initialPhaseType = initialPhase.getPhaseType(); } } } final DateTime date = plan.dateOfFirstRecurringNonZeroCharge(subscription.getStartDate(), initialPhaseType); final int bcdUTC = date.toDateTime(DateTimeZone.UTC).getDayOfMonth(); final int bcdLocal = date.toDateTime(account.getTimeZone()).getDayOfMonth(); log.info("Calculated BCD: subscription id {}, subscription start {}, timezone {}, bcd UTC {}, bcd local {}", subscription.getId(), date.toDateTimeISO(), account.getTimeZone(), bcdUTC, bcdLocal); return bcdLocal; }
From source file:com.ning.billing.recurly.QueryParams.java
License:Apache License
private String formatDate(final DateTime dateTime) { return dateTime.toDateTimeISO().toString(); }
From source file:de.zib.gndms.common.model.gorfx.types.io.ContractPropertyReader.java
License:Apache License
@SuppressWarnings({ "FeatureEnvy" }) @Override//ww w . j a v a 2 s. c o m public void read() { final @NotNull Quote con = getProduct(); if (getProperties().containsKey(SfrProperty.EST_IF_DECISION_BEFORE.key)) { DateTime dt = PropertyReadWriteAux.readISODateTime(getProperties(), SfrProperty.EST_IF_DECISION_BEFORE.key); if (dt != null) con.setAccepted(dt.toDateTimeISO()); } if (getProperties().containsKey(SfrProperty.EST_EXEC_LIKELY_UNTIL.key)) con.setDeadline( PropertyReadWriteAux.readFutureTime(getProperties(), SfrProperty.EST_EXEC_LIKELY_UNTIL.key)); if (getProperties().containsKey(SfrProperty.EST_RESULT_VALID_UNTIL.key)) con.setResultValidity( PropertyReadWriteAux.readFutureTime(getProperties(), SfrProperty.EST_RESULT_VALID_UNTIL.key)); final Object sizeProperty = getProperties().get(SfrProperty.EST_MAX_SIZE.key); if (sizeProperty != null) { final String sizePropertyStr = sizeProperty.toString().trim(); if (sizePropertyStr.length() > 0) con.setExpectedSize(Long.parseLong(sizePropertyStr)); } if (getProperties().containsKey(SfrProperty.EST_REQUEST_INFO.key)) con.setAdditionalNotes(PropertyReadWriteAux.readMap(getProperties(), SfrProperty.EST_REQUEST_INFO.key)); }
From source file:de.zib.gndms.model.gorfx.types.io.ContractPropertyReader.java
License:Apache License
@SuppressWarnings({ "FeatureEnvy" }) @Override//from ww w.j av a2s. co m public void read() { final @NotNull TransientContract con = getProduct(); String s; if (getProperties().containsKey(SfrProperty.EST_IF_DECISION_BEFORE.key)) { DateTime dt = PropertyReadWriteAux.readISODateTime(getProperties(), SfrProperty.EST_IF_DECISION_BEFORE.key); if (dt != null) con.setAccepted(dt.toDateTimeISO()); } if (getProperties().containsKey(SfrProperty.EST_EXEC_LIKELY_UNTIL.key)) con.setDeadline( PropertyReadWriteAux.readFutureTime(getProperties(), SfrProperty.EST_EXEC_LIKELY_UNTIL.key)); if (getProperties().containsKey(SfrProperty.EST_RESULT_VALID_UNTIL.key)) con.setResultValidity( PropertyReadWriteAux.readFutureTime(getProperties(), SfrProperty.EST_RESULT_VALID_UNTIL.key)); final Object sizeProperty = getProperties().get(SfrProperty.EST_MAX_SIZE.key); if (sizeProperty != null) { final String sizePropertyStr = sizeProperty.toString().trim(); if (sizePropertyStr.length() > 0) con.setExpectedSize(Long.parseLong(sizePropertyStr)); } if (getProperties().containsKey(SfrProperty.EST_REQUEST_INFO.key)) con.setAdditionalNotes(PropertyReadWriteAux.readMap(getProperties(), SfrProperty.EST_REQUEST_INFO.key)); }
From source file:nz.co.fortytwo.signalk.util.Util.java
License:Open Source License
public static String getIsoTimeString(DateTime now) { return now.toDateTimeISO().toString(); }
From source file:org.elasticsearch.xpack.ml.transforms.PainlessDomainSplitIT.java
License:Open Source License
public void testHRDSplit() throws Exception { // Create job String job = "{\n" + " \"description\":\"Domain splitting\",\n" + " \"analysis_config\" : {\n" + " \"bucket_span\":\"3600s\",\n" + " \"detectors\" :[{\"function\":\"count\", \"by_field_name\" : \"domain_split\"}]\n" + " },\n" + " \"data_description\" : {\n" + " \"field_delimiter\":\",\",\n" + " \"time_field\":\"time\"\n" + " \n" + " }\n" + " }"; client().performRequest("PUT", MachineLearning.BASE_PATH + "anomaly_detectors/hrd-split-job", Collections.emptyMap(), new StringEntity(job, ContentType.APPLICATION_JSON)); client().performRequest("POST", MachineLearning.BASE_PATH + "anomaly_detectors/hrd-split-job/_open"); // Create index to hold data Settings.Builder settings = Settings.builder().put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0); createIndex("painless", settings.build(), "\"test\": { \"properties\": { \"domain\": { \"type\": \"keyword\" }," + "\"time\": { \"type\": \"date\" } } }"); // Index some data DateTime baseTime = new DateTime().minusYears(1); TestConfiguration test = tests.get(randomInt(tests.size() - 1)); // domainSplit() tests had subdomain, testHighestRegisteredDomainCases() did not, so we need a special case for sub String expectedSub = test.subDomainExpected == null ? ".*" : test.subDomainExpected.replace(".", "\\."); String expectedHRD = test.domainExpected.replace(".", "\\."); Pattern pattern = Pattern .compile("domain_split\":\\[\"(" + expectedSub + "),(" + expectedHRD + ")\"[,\\]]"); for (int i = 0; i < 100; i++) { DateTime time = baseTime.plusHours(i); if (i == 64) { // Anomaly has 100 docs, but we don't care about the value for (int j = 0; j < 100; j++) { client().performRequest("PUT", "painless/test/" + time.toDateTimeISO() + "_" + j, Collections.emptyMap(), new StringEntity("{\"domain\": \"" + "bar.bar.com\", \"time\": \"" + time.toDateTimeISO() + "\"}", ContentType.APPLICATION_JSON)); }// ww w .ja v a2s . c om } else { // Non-anomalous values will be what's seen when the anomaly is reported client().performRequest("PUT", "painless/test/" + time.toDateTimeISO(), Collections.emptyMap(), new StringEntity("{\"domain\": \"" + test.hostName + "\", \"time\": \"" + time.toDateTimeISO() + "\"}", ContentType.APPLICATION_JSON)); } } client().performRequest("POST", "painless/_refresh"); // Create and start datafeed String body = "{\n" + " \"job_id\":\"hrd-split-job\",\n" + " \"indexes\":[\"painless\"],\n" + " \"types\":[\"test\"],\n" + " \"script_fields\": {\n" + " \"domain_split\": {\n" + " \"script\": \"return domainSplit(doc['domain'].value, params);\"\n" + " }\n" + " }\n" + " }"; client().performRequest("PUT", MachineLearning.BASE_PATH + "datafeeds/hrd-split-datafeed", Collections.emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON)); client().performRequest("POST", MachineLearning.BASE_PATH + "datafeeds/hrd-split-datafeed/_start"); boolean passed = awaitBusy(() -> { try { client().performRequest("POST", "/_refresh"); Response response = client().performRequest("GET", MachineLearning.BASE_PATH + "anomaly_detectors/hrd-split-job/results/records"); String responseBody = EntityUtils.toString(response.getEntity()); if (responseBody.contains("\"count\":2")) { Matcher m = pattern.matcher(responseBody); String actualSubDomain = ""; String actualDomain = ""; if (m.find()) { actualSubDomain = m.group(1).replace("\"", ""); actualDomain = m.group(2).replace("\"", ""); } String expectedTotal = "[" + test.subDomainExpected + "," + test.domainExpected + "]"; String actualTotal = "[" + actualSubDomain + "," + actualDomain + "]"; // domainSplit() tests had subdomain, testHighestRegisteredDomainCases() do not if (test.subDomainExpected != null) { assertThat( "Expected subdomain [" + test.subDomainExpected + "] but found [" + actualSubDomain + "]. Actual " + actualTotal + " vs Expected " + expectedTotal, actualSubDomain, equalTo(test.subDomainExpected)); } assertThat( "Expected domain [" + test.domainExpected + "] but found [" + actualDomain + "]. Actual " + actualTotal + " vs Expected " + expectedTotal, actualDomain, equalTo(test.domainExpected)); return true; } else { logger.error(responseBody); return false; } } catch (Exception e) { logger.error(e.getMessage()); return false; } }, 5, TimeUnit.SECONDS); if (!passed) { fail("Anomaly records were not found within 5 seconds"); } }
From source file:org.fenixedu.cms.domain.SiteExporter.java
License:Open Source License
private JsonElement toJson(DateTime date) { return date != null ? new JsonPrimitive(date.toDateTimeISO().toString()) : JsonNull.INSTANCE; }