List of usage examples for org.joda.time Interval Interval
public Interval(long startInstant, long endInstant, Chronology chronology)
From source file:com.netflix.ice.basic.BasicTagGroupManager.java
License:Apache License
@Override protected void poll() throws IOException { boolean downloaded = AwsUtils.downloadFileIfChanged(config.workS3BucketName, config.workS3BucketPrefix, file, 0);/* www . j a v a 2 s . c o m*/ if (downloaded || tagGroups == null) { logger.info("trying to read from " + file); DataInputStream in = new DataInputStream(new FileInputStream(file)); try { TreeMap<Long, Collection<TagGroup>> tagGroupsWithResourceGroups = TagGroup.Serializer .deserializeTagGroups(config, in); TreeMap<Long, Collection<TagGroup>> tagGroups = removeResourceGroups(tagGroupsWithResourceGroups); Interval totalInterval = null; if (tagGroups.size() > 0) { totalInterval = new Interval(tagGroups.firstKey(), new DateTime(tagGroups.lastKey()).plusMonths(1).getMillis(), DateTimeZone.UTC); } this.totalInterval = totalInterval; this.tagGroups = tagGroups; this.tagGroupsWithResourceGroups = tagGroupsWithResourceGroups; logger.info("done reading " + file); } finally { in.close(); } } }
From source file:com.nfsdb.journal.utils.Dates.java
License:Apache License
public static Interval interval(long start, long end) { if (end < start) { return new Interval(end, start, DateTimeZone.UTC); } else {//from ww w . j av a 2 s . c o m return new Interval(start, end, DateTimeZone.UTC); } }
From source file:com.nfsdb.journal.utils.Dates.java
License:Apache License
public static Interval intervalForDirName(String name, PartitionType partitionType) { switch (partitionType) { case YEAR://from w w w . j av a2 s.c o m return intervalForDate(Dates.utc(name + "-01-01T00:00:00.000Z").getMillis(), partitionType); case MONTH: return intervalForDate(Dates.utc(name + "-01T00:00:00.000Z").getMillis(), partitionType); case DAY: return intervalForDate(Dates.utc(name + "T00:00:00.000Z").getMillis(), partitionType); case NONE: if ("default".equals(name)) { return new Interval(0, Long.MAX_VALUE, DateTimeZone.UTC); } default: throw new JournalUnsupportedTypeException(partitionType); } }
From source file:com.nfsdb.journal.utils.Dates.java
License:Apache License
public static Interval intervalForDate(long timestamp, PartitionType partitionType) { switch (partitionType) { case NONE://from w w w . ja va 2s .co m return new Interval(0, Long.MAX_VALUE, DateTimeZone.UTC); default: long lo = intervalStart(timestamp, partitionType); long hi = intervalEnd(lo, partitionType); return new Interval(lo, hi, DateTimeZone.UTC); } }
From source file:de.fraunhofer.iosb.ilt.sta.model.ext.TimeInterval.java
License:Open Source License
public static TimeInterval create(long start, long end, DateTimeZone timeZone) { return new TimeInterval(new Interval(start, end, timeZone)); }
From source file:de.javakaffee.kryoserializers.jodatime.JodaIntervalSerializer.java
License:Apache License
@Override public Interval read(final Kryo kryo, final Input input, final Class<Interval> type) { long startMillis = input.readLong(true); long endMillis = input.readLong(true); final Chronology chronology = IdentifiableChronology.readChronology(input); return new Interval(startMillis, endMillis, chronology); }
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 v a 2 s . com*/ 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:io.druid.java.util.common.Intervals.java
License:Apache License
public static Interval utc(long startInstant, long endInstant) { return new Interval(startInstant, endInstant, ISOChronology.getInstanceUTC()); }