Search in sources :

Example 61 with DateTimeZone

use of org.joda.time.DateTimeZone in project killbill by killbill.

the class AccountTestUtils method createAccountData.

private static MutableAccountData createAccountData(final int billCycleDayUTC, final int billCycleDayLocal, final String phone) {
    final String externalKey = UUID.randomUUID().toString();
    final String email = UUID.randomUUID().toString().substring(0, 4) + '@' + UUID.randomUUID().toString().substring(0, 4);
    final String name = UUID.randomUUID().toString();
    final String locale = Locale.GERMANY.toString();
    final DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles");
    final int firstNameLength = name.length();
    final Currency currency = Currency.MXN;
    final UUID paymentMethodId = UUID.randomUUID();
    final String address1 = UUID.randomUUID().toString();
    final String address2 = UUID.randomUUID().toString();
    final String companyName = UUID.randomUUID().toString();
    final String city = UUID.randomUUID().toString();
    final String stateOrProvince = UUID.randomUUID().toString();
    final String country = Locale.GERMANY.getCountry();
    final String postalCode = UUID.randomUUID().toString().substring(0, 4);
    final String notes = UUID.randomUUID().toString();
    return new DefaultMutableAccountData(externalKey, email, name, firstNameLength, currency, null, false, billCycleDayLocal, paymentMethodId, timeZone, locale, address1, address2, companyName, city, stateOrProvince, country, postalCode, phone, notes, false, true);
}
Also used : Currency(org.killbill.billing.catalog.api.Currency) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) UUID(java.util.UUID) DateTimeZone(org.joda.time.DateTimeZone)

Example 62 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class SqlResource method doPost.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response doPost(final SqlQuery sqlQuery) throws SQLException, IOException {
    // This is not integrated with the experimental authorization framework.
    // (Non-trivial since we don't know the dataSources up-front)
    final PlannerResult plannerResult;
    final DateTimeZone timeZone;
    try (final DruidPlanner planner = plannerFactory.createPlanner(sqlQuery.getContext())) {
        plannerResult = planner.plan(sqlQuery.getQuery());
        timeZone = planner.getPlannerContext().getTimeZone();
        // Remember which columns are time-typed, so we can emit ISO8601 instead of millis values.
        final List<RelDataTypeField> fieldList = plannerResult.rowType().getFieldList();
        final boolean[] timeColumns = new boolean[fieldList.size()];
        final boolean[] dateColumns = new boolean[fieldList.size()];
        for (int i = 0; i < fieldList.size(); i++) {
            final SqlTypeName sqlTypeName = fieldList.get(i).getType().getSqlTypeName();
            timeColumns[i] = sqlTypeName == SqlTypeName.TIMESTAMP;
            dateColumns[i] = sqlTypeName == SqlTypeName.DATE;
        }
        final Yielder<Object[]> yielder0 = Yielders.each(plannerResult.run());
        try {
            return Response.ok(new StreamingOutput() {

                @Override
                public void write(final OutputStream outputStream) throws IOException, WebApplicationException {
                    Yielder<Object[]> yielder = yielder0;
                    try (final JsonGenerator jsonGenerator = jsonMapper.getFactory().createGenerator(outputStream)) {
                        jsonGenerator.writeStartArray();
                        while (!yielder.isDone()) {
                            final Object[] row = yielder.get();
                            jsonGenerator.writeStartObject();
                            for (int i = 0; i < fieldList.size(); i++) {
                                final Object value;
                                if (timeColumns[i]) {
                                    value = ISODateTimeFormat.dateTime().print(Calcites.calciteTimestampToJoda((long) row[i], timeZone));
                                } else if (dateColumns[i]) {
                                    value = ISODateTimeFormat.dateTime().print(Calcites.calciteDateToJoda((int) row[i], timeZone));
                                } else {
                                    value = row[i];
                                }
                                jsonGenerator.writeObjectField(fieldList.get(i).getName(), value);
                            }
                            jsonGenerator.writeEndObject();
                            yielder = yielder.next(null);
                        }
                        jsonGenerator.writeEndArray();
                        jsonGenerator.flush();
                        // End with CRLF
                        outputStream.write('\r');
                        outputStream.write('\n');
                    } finally {
                        yielder.close();
                    }
                }
            }).build();
        } catch (Throwable e) {
            // make sure to close yielder if anything happened before starting to serialize the response.
            yielder0.close();
            throw Throwables.propagate(e);
        }
    } catch (Exception e) {
        log.warn(e, "Failed to handle query: %s", sqlQuery);
        final Exception exceptionToReport;
        if (e instanceof RelOptPlanner.CannotPlanException) {
            exceptionToReport = new ISE("Cannot build plan for query: %s", sqlQuery.getQuery());
        } else {
            exceptionToReport = e;
        }
        return Response.serverError().type(MediaType.APPLICATION_JSON_TYPE).entity(jsonMapper.writeValueAsBytes(QueryInterruptedException.wrapIfNeeded(exceptionToReport))).build();
    }
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) DateTimeZone(org.joda.time.DateTimeZone) QueryInterruptedException(io.druid.query.QueryInterruptedException) SQLException(java.sql.SQLException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) DruidPlanner(io.druid.sql.calcite.planner.DruidPlanner) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ISE(io.druid.java.util.common.ISE) PlannerResult(io.druid.sql.calcite.planner.PlannerResult) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 63 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class DruidAvaticaHandlerTest method testTimestampsInResponseLosAngelesTimeZone.

@Test
public void testTimestampsInResponseLosAngelesTimeZone() throws Exception {
    final ResultSet resultSet = clientLosAngeles.createStatement().executeQuery("SELECT __time, CAST(__time AS DATE) AS t2 FROM druid.foo LIMIT 1");
    final DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles");
    final DateTime localDateTime = new DateTime("2000-01-01T00Z", timeZone);
    final List<Map<String, Object>> resultRows = getRows(resultSet);
    Assert.assertEquals(ImmutableList.of(ImmutableMap.of("__time", new Timestamp(Calcites.jodaToCalciteTimestamp(localDateTime, timeZone)), "t2", new Date(Calcites.jodaToCalciteTimestamp(localDateTime.dayOfMonth().roundFloorCopy(), timeZone)))), resultRows);
}
Also used : ResultSet(java.sql.ResultSet) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Date(java.sql.Date) Test(org.junit.Test)

Example 64 with DateTimeZone

use of org.joda.time.DateTimeZone in project joda-time-android by dlew.

the class TestDateTimeZone method testPatchedNameKeysGazaHistoric.

public void testPatchedNameKeysGazaHistoric() throws Exception {
    // the tz database does not have unique name keys [1716305]
    DateTimeZone zone = DateTimeZone.forID("Africa/Johannesburg");
    DateTime now = new DateTime(1943, 1, 1, 0, 0, 0, 0);
    String str1 = zone.getName(now.getMillis());
    String str2 = zone.getName(now.plusMonths(6).getMillis());
    assertEquals(false, str1.equals(str2));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 65 with DateTimeZone

use of org.joda.time.DateTimeZone in project joda-time-android by dlew.

the class TestDateTimeZone method testGetOffsetFixed_RI.

public void testGetOffsetFixed_RI() {
    DateTimeZone zone = DateTimeZone.forID("+01:00");
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_SUMMER)));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_WINTER)));
    assertEquals(zone.getOffset(DateTimeUtils.currentTimeMillis()), zone.getOffset(null));
}
Also used : Instant(org.joda.time.Instant) DateTimeZone(org.joda.time.DateTimeZone)

Aggregations

DateTimeZone (org.joda.time.DateTimeZone)263 DateTime (org.joda.time.DateTime)123 ArrayList (java.util.ArrayList)36 Test (org.testng.annotations.Test)35 LocalDate (org.joda.time.LocalDate)27 Test (org.junit.Test)21 TimeIntervalRounding (org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding)18 TimeUnitRounding (org.elasticsearch.common.rounding.Rounding.TimeUnitRounding)18 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)15 UUID (java.util.UUID)14 TimeFormat (org.gephi.graph.api.TimeFormat)13 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)12 Date (java.util.Date)12 Chronology (org.joda.time.Chronology)12 LocalDateTime (org.joda.time.LocalDateTime)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)11 LocalTime (org.joda.time.LocalTime)10 SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)10