Example usage for org.joda.time DateTime get

List of usage examples for org.joda.time DateTime get

Introduction

In this page you can find the example usage for org.joda.time DateTime get.

Prototype

public int get(DateTimeFieldType type) 

Source Link

Document

Get the value of one of the fields of a datetime.

Usage

From source file:se.vgregion.webbisar.types.BirthTime.java

License:Open Source License

public BirthTime() {
    Date date = new Date();
    DateTime dt = new DateTime(date);

    this.year = dt.get(DateTimeFieldType.year());
    this.month = dt.get(DateTimeFieldType.monthOfYear());
    this.day = dt.get(DateTimeFieldType.dayOfMonth());
    this.hour = dt.get(DateTimeFieldType.hourOfDay());
    this.minutes = dt.get(DateTimeFieldType.minuteOfHour());
}

From source file:se.vgregion.webbisar.types.BirthTime.java

License:Open Source License

public BirthTime(Date date) {
    DateTime dt = new DateTime(date);

    this.year = dt.get(DateTimeFieldType.year());
    this.month = dt.get(DateTimeFieldType.monthOfYear());
    this.day = dt.get(DateTimeFieldType.dayOfMonth());
    this.hour = dt.get(DateTimeFieldType.hourOfDay());
    this.minutes = dt.get(DateTimeFieldType.minuteOfHour());
}

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   ww w . ja v a 2s  .  c  om*/
    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;// w w  w  . j a  va  2s  . c o m
    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;
}

From source file:TVShowTimelineMaker.timeConstraints.dayAcceptors.SameTimeAsDayAcceptor.java

@Override
public boolean accept(DateTime inDateTime) {
    for (DayEvent<?, ?> curEvent : this.Events) {
        if (curEvent.getLastmodifyed() > this.lastmodifyed) {
            this.build();
            break;
        }/*from  www.  ja v a  2 s.  com*/
    }
    int monthOfYear = inDateTime.get(org.joda.time.DateTimeFieldType.monthOfYear());
    boolean rAccept;
    if ((!this.overYearBound) && (monthOfYear > this.startMonth) && (monthOfYear < this.endMonth)) {
        rAccept = true;
    } else if ((this.overYearBound) && ((monthOfYear > this.startMonth) || (monthOfYear < this.endMonth))) {
        rAccept = true;
    } else if ((monthOfYear == this.startMonth) && (monthOfYear == this.endMonth)) {
        rAccept = (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) >= this.startDay)
                && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) <= this.endDay);
    } else if ((monthOfYear == this.startMonth)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) >= this.startDay)) {
        rAccept = true;
    } else if ((monthOfYear == this.endMonth)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) <= this.endDay)) {
        rAccept = true;
    } else {
        rAccept = false;
    }
    return rAccept;
}

From source file:TVShowTimelineMaker.timeConstraints.dayAcceptors.SameTimeAsDayAcceptor.java

public void build() {
    DateTime buildFromStart = resetStartTime;
    DateTime buildFromEnd = resetEndTime;
    for (DayEvent<?, ?> curEvent : this.Events) {
        if (curEvent.isValid()) {
            if (curEvent instanceof OnceEvent) {
                OnceEvent<?> curOnceEvent = (OnceEvent<?>) curEvent;
                Interval curEventInterval = new Interval(curOnceEvent.getEarliestPossibleStartTime(),
                        curOnceEvent.getLatestPossibleEndTime());
                if (curEventInterval.toDuration().isShorterThan(yearOfDays.toStandardDuration())) {
                    int startYear = curOnceEvent.getEarliestPossibleStartTime()
                            .get(org.joda.time.DateTimeFieldType.year());
                    DateTime newStart = curOnceEvent.getEarliestPossibleStartTime().minusYears(startYear);
                    DateTime newEnd = curOnceEvent.getLatestPossibleEndTime().minusYears(startYear);
                    if (newStart.isAfter(buildFromStart)) {
                        buildFromStart = newStart;
                    }/*from   w  ww.  j  av  a  2  s .com*/
                    if (newEnd.isBefore(buildFromEnd)) {
                        buildFromEnd = newEnd;
                    }
                }
            } else if (curEvent instanceof YearlyDayEvent) {
                YearlyDayEvent curYearlyDayEvent = (YearlyDayEvent) curEvent;
            }
        }
    }
    this.overYearBound = buildFromEnd.get(org.joda.time.DateTimeFieldType.year()) > 0;
    this.startMonth = buildFromStart.get(org.joda.time.DateTimeFieldType.monthOfYear());
    this.startDay = buildFromStart.get(org.joda.time.DateTimeFieldType.dayOfMonth());
    this.endMonth = buildFromEnd.get(org.joda.time.DateTimeFieldType.monthOfYear());
    this.endDay = buildFromEnd.get(org.joda.time.DateTimeFieldType.dayOfMonth());
    this.lastmodifyed = System.currentTimeMillis();
}

From source file:TVShowTimelineMaker.timeConstraints.FieldChangeConstraint.java

public boolean consistentWithConstraint(DateTime inFirstDay, DateTime inSecondDay) {
    this.makeToPeriodIfNull();
    int firstValue = inFirstDay.plus(this.toPeriod).get(this.mDateTimeFieldType);
    int secondValue = inSecondDay.get(this.mDateTimeFieldType);
    return (firstValue == secondValue);
}

From source file:TVShowTimelineMaker.util.Season.java

public boolean inSeason(DateTime inDateTime) {
    int monthOfYear = inDateTime.get(org.joda.time.DateTimeFieldType.monthOfYear());
    boolean rAccept;
    if ((!this.overYearBound) && (monthOfYear > this.startMonth) && (monthOfYear < this.endMonth)) {
        rAccept = true;//from   w ww.  j a va  2 s  .co m
    } else if ((this.overYearBound) && ((monthOfYear > this.startMonth) || (monthOfYear < this.endMonth))) {
        rAccept = true;
    } else if ((this.startMonth == this.endMonth) && (monthOfYear == this.startMonth)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) >= this.startDay)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) <= this.endDay)) {
        rAccept = true;
    } else if ((this.startMonth != this.endMonth) && (monthOfYear == this.startMonth)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) >= this.startDay)) {
        rAccept = true;
    } else if ((this.startMonth != this.endMonth) && (monthOfYear == this.endMonth)
            && (inDateTime.get(org.joda.time.DateTimeFieldType.dayOfMonth()) <= this.endDay)) {
        rAccept = true;
    } else {
        rAccept = false;
    }
    return rAccept;
}