List of usage examples for org.joda.time DateTime plusWeeks
public DateTime plusWeeks(int weeks)
From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java
License:Open Source License
private Interval map(final OccupationPeriod occupationPeriod, final Integer w) { final Interval startInterval = occupationPeriod.getPeriodInterval(); final DateTime s = startInterval.getStart().plusWeeks(w - 1); final Interval i = new Interval(s, s.plusWeeks(1)); return intersect(occupationPeriod, i); }
From source file:stroom.index.server.IndexShardKeyUtil.java
License:Apache License
public static IndexShardKey createTimeBasedKey(final Index index, final long timeMs, final int shardNo) { String partition = ALL;/*from w ww. j ava 2s.c o m*/ DateTime dateFrom = null; DateTime dateTo = null; if (index.getPartitionBy() != null && index.getPartitionSize() > 0) { dateFrom = new DateTime(timeMs); if (PartitionBy.YEAR.equals(index.getPartitionBy())) { int year = dateFrom.get(DateTimeFieldType.year()); year = fix(year, index.getPartitionSize()); dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateTo = dateFrom.plusYears(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 4); } else if (PartitionBy.MONTH.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int month = dateFrom.get(DateTimeFieldType.monthOfYear()); month = fix(month, index.getPartitionSize()); if (month < 1) { month = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusMonths(month - 1); dateTo = dateFrom.plusMonths(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 7); } else if (PartitionBy.WEEK.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int week = dateFrom.get(DateTimeFieldType.weekOfWeekyear()); week = fix(week, index.getPartitionSize()); if (week < 1) { week = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusWeeks(week - 1); dateTo = dateFrom.plusWeeks(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 10); } else if (PartitionBy.DAY.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int day = dateFrom.get(DateTimeFieldType.dayOfYear()); day = fix(day, index.getPartitionSize()); if (day < 1) { day = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusDays(day - 1); dateTo = dateFrom.plusDays(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 10); } } Long partitionFromTime = null; if (dateFrom != null) { partitionFromTime = dateFrom.getMillis(); } Long partitionToTime = null; if (dateTo != null) { partitionToTime = dateTo.getMillis(); } return new IndexShardKey(index, partition, partitionFromTime, partitionToTime, shardNo); }
From source file:stroom.index.server.IndexShardKeyUtil.java
License:Apache License
private static String getTimeBasedPartitionName(final Index index, final long timeMs) { String partition = ALL;/*from w w w.ja v a 2s .c om*/ if (index.getPartitionBy() != null && index.getPartitionSize() > 0) { DateTime dateTime = new DateTime(timeMs); if (PartitionBy.YEAR.equals(index.getPartitionBy())) { int year = dateTime.get(DateTimeFieldType.year()); year = fix(year, index.getPartitionSize()); dateTime = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); partition = DateUtil.createFileDateTimeString(dateTime.getMillis()); partition = partition.substring(0, 4); } else if (PartitionBy.MONTH.equals(index.getPartitionBy())) { final int year = dateTime.get(DateTimeFieldType.year()); int month = dateTime.get(DateTimeFieldType.monthOfYear()); month = fix(month, index.getPartitionSize()); if (month < 1) { month = 1; } dateTime = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateTime = dateTime.plusMonths(month - 1); partition = DateUtil.createFileDateTimeString(dateTime.getMillis()); partition = partition.substring(0, 7); } else if (PartitionBy.WEEK.equals(index.getPartitionBy())) { final int year = dateTime.get(DateTimeFieldType.year()); int week = dateTime.get(DateTimeFieldType.weekOfWeekyear()); week = fix(week, index.getPartitionSize()); if (week < 1) { week = 1; } dateTime = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateTime = dateTime.plusWeeks(week - 1); partition = DateUtil.createFileDateTimeString(dateTime.getMillis()); partition = partition.substring(0, 10); } else if (PartitionBy.DAY.equals(index.getPartitionBy())) { final int year = dateTime.get(DateTimeFieldType.year()); int day = dateTime.get(DateTimeFieldType.dayOfYear()); day = fix(day, index.getPartitionSize()); if (day < 1) { day = 1; } dateTime = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateTime = dateTime.plusDays(day - 1); partition = DateUtil.createFileDateTimeString(dateTime.getMillis()); partition = partition.substring(0, 10); } } return partition; }