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);
}
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();
}
}
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);
}
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));
}
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));
}
Aggregations