use of org.joda.time.DurationFieldType in project CoreNLP by stanfordnlp.
the class JodaTimeUtils method discardMoreSpecificFields.
public static Period discardMoreSpecificFields(Period p, DurationFieldType dft, Chronology chronology) {
DurationField df = dft.getField(chronology);
Period res = new Period();
for (int i = 0; i < p.size(); i++) {
DurationFieldType fieldType = p.getFieldType(i);
DurationField f = fieldType.getField(chronology);
int cmp = df.compareTo(f);
if (cmp <= 0) {
res = res.withField(fieldType, p.getValue(i));
}
}
return res;
}
use of org.joda.time.DurationFieldType in project CoreNLP by stanfordnlp.
the class JodaTimeUtils method isMoreSpecific.
// Returns if df1 is more specific than df2
public static boolean isMoreSpecific(DateTimeFieldType df1, DateTimeFieldType df2, Chronology chronology) {
DurationFieldType df1DurationFieldType = df1.getDurationType();
DurationFieldType df2DurationFieldType = df2.getDurationType();
if (!df2DurationFieldType.equals(df1DurationFieldType)) {
DurationField df2Unit = df2DurationFieldType.getField(chronology);
DurationFieldType p = df1.getRangeDurationType();
if (p != null) {
DurationField df1Unit = df1DurationFieldType.getField(chronology);
int cmp = df1Unit.compareTo(df2Unit);
if (cmp < 0) {
return true;
}
}
}
return false;
}
use of org.joda.time.DurationFieldType in project CoreNLP by stanfordnlp.
the class JodaTimeUtils method getJodaTimePeriod.
protected static Period getJodaTimePeriod(Partial p) {
if (p.size() > 0) {
DateTimeFieldType dtType = p.getFieldType(p.size() - 1);
DurationFieldType dType = dtType.getDurationType();
Period period = new Period();
if (period.isSupported(dType)) {
return period.withField(dType, 1);
} else {
DurationField df = dType.getField(p.getChronology());
if (df instanceof ScaledDurationField) {
ScaledDurationField sdf = (ScaledDurationField) df;
return period.withField(sdf.getWrappedField().getType(), sdf.getScalar());
}
// PeriodType.forFields(new DurationFieldType[]{dType});
// return new Period(df.getUnitMillis(), PeriodType.forFields(new DurationFieldType[]{dType}));
}
}
return null;
}
use of org.joda.time.DurationFieldType in project CoreNLP by stanfordnlp.
the class JodaTimeUtils method padMoreSpecificFields.
public static Partial padMoreSpecificFields(Partial p, Period granularity) {
DateTimeFieldType msf = getMostSpecific(p);
if (isMoreGeneral(msf, DateTimeFieldType.year(), p.getChronology()) || isMoreGeneral(msf, DateTimeFieldType.yearOfCentury(), p.getChronology())) {
if (p.isSupported(DateTimeFieldType.yearOfCentury())) {
// OKAY
} else {
if (p.isSupported(JodaTimeUtils.DecadeOfCentury)) {
if (p.isSupported(DateTimeFieldType.centuryOfEra())) {
int year = p.get(DateTimeFieldType.centuryOfEra()) * 100 + p.get(JodaTimeUtils.DecadeOfCentury) * 10;
p = p.without(JodaTimeUtils.DecadeOfCentury);
p = p.without(DateTimeFieldType.centuryOfEra());
p = p.with(DateTimeFieldType.year(), year);
} else {
int year = p.get(JodaTimeUtils.DecadeOfCentury) * 10;
p = p.without(JodaTimeUtils.DecadeOfCentury);
p = p.with(DateTimeFieldType.yearOfCentury(), year);
}
} else {
if (p.isSupported(DateTimeFieldType.centuryOfEra())) {
int year = p.get(DateTimeFieldType.centuryOfEra()) * 100;
p = p.without(DateTimeFieldType.centuryOfEra());
p = p.with(DateTimeFieldType.year(), year);
}
}
}
}
boolean useWeek = false;
if (p.isSupported(DateTimeFieldType.weekOfWeekyear())) {
if (!p.isSupported(DateTimeFieldType.dayOfMonth()) && !p.isSupported(DateTimeFieldType.dayOfWeek())) {
p = p.with(DateTimeFieldType.dayOfWeek(), 1);
if (p.isSupported(DateTimeFieldType.monthOfYear())) {
p = p.without(DateTimeFieldType.monthOfYear());
}
}
useWeek = true;
}
Partial p2 = useWeek ? EMPTY_ISO_WEEK_PARTIAL : EMPTY_ISO_PARTIAL;
for (int i = 0; i < p2.size(); i++) {
DateTimeFieldType fieldType = p2.getFieldType(i);
if (msf == null || isMoreSpecific(fieldType, msf, p.getChronology())) {
if (!p.isSupported(fieldType)) {
if (fieldType == DateTimeFieldType.monthOfYear()) {
if (p.isSupported(QuarterOfYear)) {
p = p.with(DateTimeFieldType.monthOfYear(), (p.get(QuarterOfYear) - 1) * 3 + 1);
continue;
} else if (p.isSupported(HalfYearOfYear)) {
p = p.with(DateTimeFieldType.monthOfYear(), (p.get(HalfYearOfYear) - 1) * 6 + 1);
continue;
}
}
p = p.with(fieldType, p2.getValue(i));
}
}
}
if (granularity != null) {
DurationFieldType mostSpecific = getMostSpecific(granularity);
p = discardMoreSpecificFields(p, mostSpecific);
}
return p;
}
use of org.joda.time.DurationFieldType in project gephi by gephi.
the class DateTick method create.
public static DateTick create(double min, double max, int width) {
DateTime minDate = new DateTime((long) min);
DateTime maxDate = new DateTime((long) max);
Period period = new Period(minDate, maxDate, PeriodType.yearMonthDayTime());
int years = period.getYears();
int months = period.getMonths();
int days = period.getDays();
int hours = period.getHours();
int minutes = period.getMinutes();
int seconds = period.getSeconds();
//Top type
DateTimeFieldType topType;
if (years > 0) {
topType = DateTimeFieldType.year();
} else if (months > 0) {
topType = DateTimeFieldType.monthOfYear();
} else if (days > 0) {
topType = DateTimeFieldType.dayOfMonth();
} else if (hours > 0) {
topType = DateTimeFieldType.hourOfDay();
} else if (minutes > 0) {
topType = DateTimeFieldType.minuteOfHour();
} else if (seconds > 0) {
topType = DateTimeFieldType.secondOfMinute();
} else {
topType = DateTimeFieldType.millisOfSecond();
}
//Bottom type
if (topType != DateTimeFieldType.millisOfSecond()) {
DateTimeFieldType bottomType;
if (topType.equals(DateTimeFieldType.year())) {
bottomType = DateTimeFieldType.monthOfYear();
} else if (topType.equals(DateTimeFieldType.monthOfYear())) {
bottomType = DateTimeFieldType.dayOfMonth();
} else if (topType.equals(DateTimeFieldType.dayOfMonth())) {
bottomType = DateTimeFieldType.hourOfDay();
} else if (topType.equals(DateTimeFieldType.hourOfDay())) {
bottomType = DateTimeFieldType.minuteOfHour();
} else if (topType.equals(DateTimeFieldType.minuteOfHour())) {
bottomType = DateTimeFieldType.secondOfMinute();
} else {
bottomType = DateTimeFieldType.millisOfSecond();
}
//Number of ticks
Period p = new Period(minDate, maxDate, PeriodType.forFields(new DurationFieldType[] { bottomType.getDurationType() }));
int intervals = p.get(bottomType.getDurationType());
if (intervals > 0) {
int intervalSize = width / intervals;
if (intervalSize >= MIN_PIXELS) {
return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType, bottomType });
}
}
}
return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType });
}
Aggregations