List of usage examples for org.joda.time DateTimeZone forTimeZone
public static DateTimeZone forTimeZone(TimeZone zone)
From source file:com.esofthead.mycollab.core.utils.TimezoneVal.java
License:Open Source License
private static String getOffsetString(TimeZone timeZone) { int offsetInMillis = DateTimeZone.forTimeZone(timeZone).getOffset(new DateTime().getMillis()); String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60)); offset = "(GMT" + (offsetInMillis >= 0 ? "+" : "-") + offset + ")"; return offset; }
From source file:com.esofthead.mycollab.vaadin.AppContext.java
License:Open Source License
/** * @param date is the UTC date value//from w w w .j av a2 s. co m * @return */ public static String formatDateTime(Date date) { // return date == null ? "" : DateTimeUtils.formatDate(date, AppContext.getDateTimeFormat(), AppContext.getUserTimeZone()); if (date == null) { return ""; } else { DateTime jodaDate = new DateTime(date) .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())); if (jodaDate.getHourOfDay() > 0 || jodaDate.getMinuteOfHour() > 0) { DateTimeFormatter formatter = DateTimeFormat.forPattern(AppContext.getDateTimeFormat()); return formatter.print(jodaDate); } else { DateTimeFormatter formatter = DateTimeFormat.forPattern(AppContext.getDateFormat()); return formatter.print(jodaDate); } } }
From source file:com.esofthead.mycollab.vaadin.web.ui.field.DateTimeOptionField.java
License:Open Source License
@Override public void setPropertyDataSource(Property newDataSource) { Date value = (Date) newDataSource.getValue(); if (value != null) { DateTime jodaTime = new DateTime(value); jodaTime = jodaTime.toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())); int hrs = jodaTime.getHourOfDay(); int min = jodaTime.getMinuteOfHour(); String timeFormat = "AM"; if (hrs > 12) { hrs -= 12;/* ww w .j av a 2 s . c o m*/ timeFormat = "PM"; } if ((hrs > 0 || min > 0) && hideTimeOption) { toggleHideTimeOption(false); } popupDateField.setPropertyDataSource(new ObjectProperty(jodaTime.toDate())); if (!hideTimeOption) { hourPickerComboBox.setPropertyDataSource(new ObjectProperty((hrs < 10) ? "0" + hrs : "" + hrs)); minutePickerComboBox.setPropertyDataSource(new ObjectProperty((min < 10) ? "0" + min : "" + min)); timeFormatComboBox.setPropertyDataSource(new ObjectProperty(timeFormat)); } } super.setPropertyDataSource(newDataSource); }
From source file:com.esofthead.mycollab.vaadin.web.ui.field.DateTimeOptionField.java
License:Open Source License
private Date getDateValue() { Date selectDate = popupDateField.getValue(); if (selectDate == null) { return null; }/*w ww . j ava 2s. c o m*/ DateTime jodaSelectDate = new DateTime(selectDate) .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())); Date baseDate = new LocalDate(jodaSelectDate).toDate(); if (hideTimeOption) { return new LocalDateTime(baseDate).toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())) .toDate(); } else { Integer hour = (hourPickerComboBox.getValue() != null) ? Integer.parseInt((String) hourPickerComboBox.getValue()) : 0; Integer minus = (minutePickerComboBox.getValue() != null) ? Integer.parseInt((String) minutePickerComboBox.getValue()) : 0; String timeFormat = (timeFormatComboBox.getValue() != null) ? (String) timeFormatComboBox.getValue() : "AM"; long milliseconds = calculateMilliSeconds(hour, minus, timeFormat); DateTime jodaTime = new DateTime(baseDate).plus(new Duration(milliseconds)); return new LocalDateTime(jodaTime.getMillis()) .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())).toDate(); } }
From source file:com.evolveum.midpoint.web.component.DateInput.java
License:Apache License
public Date computeDateTime() { Date dateFieldInput = getDate(); if (dateFieldInput == null) { return null; }//from ww w. j a va 2 s .com Integer hoursInput = getHours(); Integer minutesInput = getMinutes(); AM_PM amOrPmInput = getAmOrPm(); // Get year, month and day ignoring any timezone of the Date object Calendar cal = Calendar.getInstance(); cal.setTime(dateFieldInput); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hours = (hoursInput == null ? 0 : hoursInput % 24); int minutes = (minutesInput == null ? 0 : minutesInput); // Use the input to create a date object with proper timezone MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0, DateTimeZone.forTimeZone(getClientTimeZone())); // Adjust for halfday if needed if (use12HourFormat()) { int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0); date.set(DateTimeFieldType.halfdayOfDay(), halfday); date.set(DateTimeFieldType.hourOfHalfday(), hours % 12); } // The date will be in the server's timezone return newDateInstance(date.getMillis()); }
From source file:com.facebook.presto.atop.AtopConnectorConfig.java
License:Apache License
public DateTimeZone getDateTimeZone() { return DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZone)); }
From source file:com.facebook.presto.hive.AbstractTestHiveClient.java
License:Apache License
protected void setupHive(String connectorId, String databaseName, String timeZoneId) { database = databaseName;/*from w w w . j av a 2 s . com*/ table = new SchemaTableName(database, "presto_test"); tableUnpartitioned = new SchemaTableName(database, "presto_test_unpartitioned"); tableOffline = new SchemaTableName(database, "presto_test_offline"); tableOfflinePartition = new SchemaTableName(database, "presto_test_offline_partition"); view = new SchemaTableName(database, "presto_test_view"); invalidTable = new SchemaTableName(database, INVALID_TABLE); tableBucketedStringInt = new SchemaTableName(database, "presto_test_bucketed_by_string_int"); tableBucketedBigintBoolean = new SchemaTableName(database, "presto_test_bucketed_by_bigint_boolean"); tableBucketedDoubleFloat = new SchemaTableName(database, "presto_test_bucketed_by_double_float"); temporaryCreateTable = new SchemaTableName(database, "tmp_presto_test_create_" + randomName()); temporaryCreateSampledTable = new SchemaTableName(database, "tmp_presto_test_create_" + randomName()); temporaryCreateView = new SchemaTableName(database, "tmp_presto_test_create_" + randomName()); tableOwner = "presto_test"; invalidTableHandle = new HiveTableHandle("hive", database, INVALID_TABLE, SESSION); dsColumn = new HiveColumnHandle(connectorId, "ds", 0, HiveType.STRING, -1, true); fileFormatColumn = new HiveColumnHandle(connectorId, "file_format", 1, HiveType.STRING, -1, true); dummyColumn = new HiveColumnHandle(connectorId, "dummy", 2, HiveType.INT, -1, true); intColumn = new HiveColumnHandle(connectorId, "t_int", 0, HiveType.INT, -1, true); invalidColumnHandle = new HiveColumnHandle(connectorId, INVALID_COLUMN, 0, HiveType.STRING, 0, false); partitions = ImmutableSet.<ConnectorPartition>of( new HivePartition( table, "ds=2012-12-29/file_format=rcfile-text/dummy=0", ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(dsColumn, utf8Slice("2012-12-29"), fileFormatColumn, utf8Slice("rcfile-text"), dummyColumn, 0L), Optional.<HiveBucket>absent()), new HivePartition(table, "ds=2012-12-29/file_format=rcfile-binary/dummy=2", ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(dsColumn, utf8Slice("2012-12-29"), fileFormatColumn, utf8Slice("rcfile-binary"), dummyColumn, 2L), Optional.<HiveBucket>absent()), new HivePartition(table, "ds=2012-12-29/file_format=sequencefile/dummy=4", ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(dsColumn, utf8Slice("2012-12-29"), fileFormatColumn, utf8Slice("sequencefile"), dummyColumn, 4L), Optional.<HiveBucket>absent()), new HivePartition(table, "ds=2012-12-29/file_format=textfile/dummy=6", ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(dsColumn, utf8Slice("2012-12-29"), fileFormatColumn, utf8Slice("textfile"), dummyColumn, 6L), Optional.<HiveBucket>absent())); unpartitionedPartitions = ImmutableSet.<ConnectorPartition>of(new HivePartition(tableUnpartitioned)); invalidPartition = new HivePartition(invalidTable, "unknown", ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(), Optional.<HiveBucket>absent()); timeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)); }
From source file:com.facebook.presto.hive.HiveClient.java
License:Apache License
@Inject public HiveClient(HiveConnectorId connectorId, HiveClientConfig hiveClientConfig, HiveMetastore metastore, NamenodeStats namenodeStats, HdfsEnvironment hdfsEnvironment, DirectoryLister directoryLister, @ForHiveClient ExecutorService executorService) { this(connectorId, metastore, namenodeStats, hdfsEnvironment, directoryLister, DateTimeZone.forTimeZone(hiveClientConfig.getTimeZone()), new BoundedExecutor(executorService, hiveClientConfig.getMaxGlobalSplitIteratorThreads()), hiveClientConfig.getMaxSplitSize(), hiveClientConfig.getMaxOutstandingSplits(), hiveClientConfig.getMaxSplitIteratorThreads(), hiveClientConfig.getMinPartitionBatchSize(), hiveClientConfig.getMaxPartitionBatchSize(), hiveClientConfig.getMaxInitialSplitSize(), hiveClientConfig.getMaxInitialSplits(), hiveClientConfig.getAllowDropTable(), hiveClientConfig.getHiveStorageFormat(), false); }
From source file:com.facebook.presto.hive.HiveSplitManager.java
License:Apache License
@Inject public HiveSplitManager(HiveConnectorId connectorId, HiveClientConfig hiveClientConfig, HiveMetastore metastore, NamenodeStats namenodeStats, HdfsEnvironment hdfsEnvironment, DirectoryLister directoryLister, @ForHiveClient ExecutorService executorService) { this(connectorId, metastore, namenodeStats, hdfsEnvironment, directoryLister, DateTimeZone.forTimeZone(hiveClientConfig.getTimeZone()), new BoundedExecutor(executorService, hiveClientConfig.getMaxSplitIteratorThreads()), hiveClientConfig.getMaxOutstandingSplits(), hiveClientConfig.getMinPartitionBatchSize(), hiveClientConfig.getMaxPartitionBatchSize(), hiveClientConfig.getMaxSplitSize(), hiveClientConfig.getMaxInitialSplitSize(), hiveClientConfig.getMaxInitialSplits(), hiveClientConfig.isForceLocalScheduling(), hiveClientConfig.isAssumeCanonicalPartitionKeys(), hiveClientConfig.getRecursiveDirWalkerEnabled()); }
From source file:com.facebook.presto.jdbc.ext.PrestoResultSet.java
License:Apache License
@Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { return getDate(columnIndex, DateTimeZone.forTimeZone(cal.getTimeZone())); }