List of usage examples for org.joda.time DateTimeZone setDefault
public static void setDefault(DateTimeZone zone) throws SecurityException
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOHoursBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//from w w w . ja va2 s . c o m // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Hours h = Hours.hoursBetween(endDate, startDate); long hours = h.getHours(); return hours; }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOMinutesBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//from w w w .j av a2 s . com // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Minutes m = Minutes.minutesBetween(endDate, startDate); long minutes = m.getMinutes(); return minutes; }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOMonthsBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//from w w w . j ava2s .c o m // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger value first Months m = Months.monthsBetween(endDate, startDate); long months = m.getMonths(); return months; }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOSecondsBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }/*from w w w . j a v a2s .com*/ // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Seconds s = Seconds.secondsBetween(endDate, startDate); long seconds = s.getSeconds(); return seconds; }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOYearsBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//from ww w . j a va2 s . c o m // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger value first Years y = Years.yearsBetween(endDate, startDate); long years = y.getYears(); return years; }
From source file:org.apache.pig.piggybank.evaluation.datetime.truncate.ISOHelper.java
License:Apache License
/** * @param input a non-null, non-empty Tuple, * whose first element is a ISO 8601 string representation of a date, time, or dateTime; * with optional time zone.//from www. j a v a 2 s .c o m * @return a DateTime representing the date, * with DateTimeZone set to the time zone parsed from the string, * or else DateTimeZone.defaultTimeZone() if one is set, * or else UTC. * @throws ExecException if input is a malformed or empty tuple. * This method is public so that it can be tested in TestTruncateDateTime. * Otherwise, it would have "package" visibility. */ public static DateTime parseDateTime(Tuple input) throws ExecException { // Save previous default time zone for restore later. DateTimeZone previousDefaultTimeZone = DateTimeZone.getDefault(); // Temporarily set default time zone to UTC, for this parse. DateTimeZone.setDefault(DEFAULT_DATE_TIME_ZONE); String isoDateString = input.get(0).toString(); DateTime dt = ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(isoDateString); // restore previous default TimeZone. DateTimeZone.setDefault(previousDefaultTimeZone); return dt; }
From source file:org.apache.sqoop.connector.jdbc.oracle.util.OracleQueries.java
License:Apache License
public static void setConnectionTimeZone(Connection connection, String timeZone) { String timeZoneStr = timeZone; if (StringUtils.isEmpty(timeZoneStr)) { timeZoneStr = "GMT"; }//from www .j av a 2s. c o m TimeZone timeZoneObj = TimeZone.getTimeZone(timeZoneStr); try { Method methSession = oracleConnectionClass.getMethod("setSessionTimeZone", String.class); Method methDefault = oracleConnectionClass.getMethod("setDefaultTimeZone", TimeZone.class); methSession.invoke(connection, timeZoneObj.getID()); methDefault.invoke(connection, timeZoneObj); TimeZone.setDefault(timeZoneObj); DateTimeZone.setDefault(DateTimeZone.forTimeZone(timeZoneObj)); LOG.info("Session Time Zone set to " + timeZoneObj.getID()); } catch (Exception e) { LOG.error("Error setting time zone: " + e.getMessage()); } }
From source file:org.apereo.portal.test.TimeZoneTestUtils.java
License:Apache License
public void beforeTest() { defaultTimeZone = TimeZone.getDefault(); defaultDateTimeZone = DateTimeZone.getDefault(); defaultUserTimezone = System.getProperty("user.timezone"); TimeZone.setDefault(testTimeZone.toTimeZone()); DateTimeZone.setDefault(testTimeZone); System.setProperty("user.timezone", testTimeZone.getID()); }
From source file:org.apereo.portal.test.TimeZoneTestUtils.java
License:Apache License
public void afterTest() { if (defaultTimeZone != null) { TimeZone.setDefault(defaultTimeZone); }/*from w ww . ja va 2 s .c o m*/ if (defaultDateTimeZone != null) { DateTimeZone.setDefault(defaultDateTimeZone); } if (defaultUserTimezone != null) { System.setProperty("user.timezone", defaultUserTimezone); } }
From source file:org.archive.bacon.ParseTimestamp.java
License:Apache License
public String exec(Tuple input) throws IOException { if (input == null || input.size() == 0) return null; try {// w w w .j a va2s .co m String date = (String) input.get(0); int len = date.length(); String format = null; if (len == 12) format = "YYYYMMddHHmm"; if (len == 14) format = "YYYYMMddHHmmss"; if (len == 20) format = "YYYY-MM-dd'T'HH:mm:ss'Z'"; if (format == null) return null; // Unknown format. // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); // See http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html DateTimeFormatter parser = DateTimeFormat.forPattern(format); DateTime result = parser.parseDateTime(date); return result.toString(); } catch (Exception e) { // If we have any problems parsing the date, just return null; return null; } }