List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:gobblin.ingestion.google.webmaster.GoogleWebmasterDayPartitioner.java
License:Apache License
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(DATE_COLUMN).toString(); DateTime date = GoogleWebmasterExtractor.dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else {//from w ww . j a va2 s .co m partition.put(PARTITION_COLUMN_PREFIX, _prefix); } } if (_withColumnNames) { partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear()); partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth()); } else { partition.put(PARTITION_COLUMN_YEAR, date.getYear()); partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth()); } return partition; }
From source file:gobblin.util.TimeRangeChecker.java
License:Apache License
/** * Checks if a specified time is on a day that is specified the a given {@link List} of acceptable days, and that the * hours + minutes of the specified time fall into a range defined by startTimeStr and endTimeStr. * * @param days is a {@link List} of days, if the specified {@link DateTime} does not have a day that falls is in this * {@link List} then this method will return false. * @param startTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param endTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param currentTime is a {@link DateTime} for which this method will check if it is in the given {@link List} of * days and falls into the time range defined by startTimeStr and endTimeStr. * * @return true if the given time is in the defined range, false otherwise. *//*w w w . j a va 2s . co m*/ public static boolean isTimeInRange(List<String> days, String startTimeStr, String endTimeStr, DateTime currentTime) { if (!Iterables.any(days, new AreDaysEqual(DAYS_OF_WEEK.get(currentTime.getDayOfWeek())))) { return false; } DateTime startTime = null; DateTime endTime = null; try { startTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(startTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "startTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } try { endTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(endTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "endTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); Interval interval = new Interval(startTime.getMillis(), endTime.getMillis(), DATE_TIME_ZONE); return interval.contains(currentTime.getMillis()); }
From source file:google.registry.model.common.TimeOfYear.java
License:Open Source License
/** * Constructs a {@link TimeOfYear} from a {@link DateTime}. * * <p>This handles leap years in an intentionally peculiar way by always treating February 29 as * February 28. It is impossible to construct a {@link TimeOfYear} for February 29th. *///w w w.j av a 2 s. c om public static TimeOfYear fromDateTime(DateTime dateTime) { DateTime nextYear = dateTime.plusYears(1); // This turns February 29 into February 28. TimeOfYear instance = new TimeOfYear(); instance.timeString = String.format("%02d %02d %08d", nextYear.getMonthOfYear(), nextYear.getDayOfMonth(), nextYear.getMillisOfDay()); return instance; }
From source file:Implement.Service.CommonServiceImpl.java
@Override public String getToDateInMillisecond() { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth()); return String.valueOf(result.getTime() + Long.valueOf("86400000")); }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String getProviderTrippDash(int providerID) { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth()); long currentTime = Long.valueOf(result.getTime() + Long.valueOf("86400000")); long last30Day = currentTime - Long.valueOf("2592000000"); return gson.toJson(providerDAO.getProviderTrippDash(providerID, currentTime, last30Day)); }
From source file:influent.server.dataaccess.DataAccessHelper.java
License:MIT License
public static String format(DateTime dateTime) { if (dateTime == null) { return null; }/* w w w . j a v a2 s . c om*/ StringBuilder s = new StringBuilder(10); s.append(dateTime.getYear()); s.append('-'); pad00(dateTime.getMonthOfYear(), s); s.append('-'); pad00(dateTime.getDayOfMonth(), s); s.append(' '); pad00(dateTime.getHourOfDay(), s); s.append(':'); pad00(dateTime.getMinuteOfHour(), s); s.append(':'); pad00(dateTime.getSecondOfMinute(), s); s.append('.'); int ms = dateTime.getMillisOfSecond(); if (ms < 100) { s.append('0'); } pad00(ms, s); return s.toString(); }
From source file:influent.server.utilities.ConstrainedDateRange.java
License:MIT License
/** * Constructs a date range that is constrained to begin and end on instances of the specified * interval, and that is guaranteed to include the range specified. * /*from w ww . j a v a 2 s . c o m*/ * @param start * @param interval * @param numBins */ public ConstrainedDateRange(DateTime start, FL_DateInterval interval, long numBins) { super(start.getMillis(), interval, numBins); DateTime constrained = start; // constrain to start of interval. switch (interval) { case SECONDS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), start.getMinuteOfHour(), start.getSecondOfMinute(), DateTimeZone.UTC); break; case HOURS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), 0, DateTimeZone.UTC); break; case DAYS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); break; case WEEKS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); final int days = start.getDayOfWeek() % 7; final long rewindMillis = days * DateTimeConstants.MILLIS_PER_DAY; constrained = new DateTime(constrained.getMillis() - rewindMillis, constrained.getZone()); break; case MONTHS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; case QUARTERS: constrained = new DateTime(start.getYear(), 1 + 3 * ((start.getMonthOfYear() - 1) / 3), 1, 0, 0, DateTimeZone.UTC); break; case YEARS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; } // add an extra partial interval at the end when not large enough. if (!start.equals(constrained)) { //System.out.println(start + " -> " + constrained); setStartDate(constrained.getMillis()); setNumBins(numBins + 1); } }
From source file:influent.server.utilities.DateTimeParser.java
License:MIT License
/** * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html#parse(java.lang.String) *//*from w w w.j a va 2 s .c o m*/ public static DateTime parse(String str) { if (str == null || str.isEmpty()) return null; // if we can, just pick out the date because we need to ignore any time zone information. if (str.length() >= 10) { try { int yyyy = Integer.parseInt(str.substring(0, 4)); int mm = Integer.parseInt(str.substring(5, 7)); int dd = Integer.parseInt(str.substring(8, 10)); // extra sanity check switch (str.charAt(4)) { case '-': case '/': return new DateTime(yyyy, mm, dd, 0, 0, 0, DateTimeZone.UTC); } } catch (Exception e) { } } final DateTime d = ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(str); return new DateTime(d.getYear(), d.getMonthOfYear(), d.getDayOfMonth(), 0, 0, 0, DateTimeZone.UTC); }
From source file:io.coala.xml.XmlUtil.java
License:Apache License
/** * @param date/*from ww w .j a v a 2 s . co m*/ * @return a JAXP {@link XMLGregorianCalendar} */ public static XMLGregorianCalendar toDateTime(final DateTime date) { final XMLGregorianCalendar result = getDatatypeFactory().newXMLGregorianCalendar(); result.setYear(date.getYear()); result.setMonth(date.getMonthOfYear()); result.setDay(date.getDayOfMonth()); result.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), date.getMillisOfSecond()); result.setTimezone(date.getZone().toTimeZone().getRawOffset() / 1000 / 60); // result.setTimezone(DatatypeConstants.FIELD_UNDEFINED); return result; }
From source file:io.github.romankl.bitcoinvalue.util.DateUtility.java
License:Open Source License
public static String convertDateToShort(String date) { if (isNullOrEmpty(date)) return ""; DateTime dateTime = new DateTime(date); String month;/*w w w . j a v a 2 s . co m*/ String day; month = String.valueOf(dateTime.getMonthOfYear()); day = String.valueOf(dateTime.getDayOfMonth()); return day + "." + month; }