Java Code Examples for org.joda.time.Period#getYears()
The following examples show how to use
org.joda.time.Period#getYears() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutionCourse.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public WeeklyWorkLoadView(final Interval executionPeriodInterval) { this.executionPeriodInterval = executionPeriodInterval; final Period period = executionPeriodInterval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; numberResponses = new int[numberOfWeeks]; contactSum = new int[numberOfWeeks]; autonomousStudySum = new int[numberOfWeeks]; otherSum = new int[numberOfWeeks]; totalSum = new int[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = executionPeriodInterval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } }
Example 2
Source File: WeeklyWorkLoadDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public CurricularYearWeeklyWorkLoadView(final DegreeCurricularPlan degreeCurricularPlan, final ExecutionSemester executionSemester, final Set<ExecutionCourse> executionCourses) { final ExecutionDegree executionDegree = findExecutionDegree(executionSemester, degreeCurricularPlan); if (executionDegree != null) { this.interval = new Interval(new DateMidnight(getBegginingOfLessonPeriod(executionSemester, executionDegree)), new DateMidnight(getEndOfExamsPeriod(executionSemester, executionDegree))); final Period period = interval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = interval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } this.executionCourses.addAll(executionCourses); } }
Example 3
Source File: DateTimeService.java From hawkular-metrics with Apache License 2.0 | 6 votes |
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); } return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
Example 4
Source File: InstallmentForFirstTimeStudents.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private int getNumberOfMonthsToChargePenalty(final Event event, final DateTime when) { final Period period = new Period(getWhenStartToApplyPenalty(event, when), when.toDateMidnight()); final int numberOfMonths = (period.getYears() * 12) + (period.getMonths() + 1); if (getMaxMonthsToApplyPenalty() == null) { return numberOfMonths; } else { return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty(); } }
Example 5
Source File: InstallmentWithMonthlyPenalty.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
protected int getNumberOfMonthsToChargePenalty(DateTime when) { final Period period = new Period(getWhenStartToApplyPenalty().withDayOfMonth(1).toDateMidnight(), when.toDateMidnight()); final int numberOfMonths = (period.getYears() * 12) + (period.getMonths() + 1); if (getMaxMonthsToApplyPenalty() == null) { return numberOfMonths; } else { return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty(); } }
Example 6
Source File: DremioStringUtils.java From dremio-oss with Apache License 2.0 | 5 votes |
/** * Formats a period similar to Oracle INTERVAL YEAR TO MONTH data type<br> * For example, the string "+21-02" defines an interval of 21 years and 2 months */ public static String formatIntervalYear(final Period p) { long months = p.getYears() * (long) DateUtility.yearsToMonths + p.getMonths(); boolean neg = false; if (months < 0) { months = -months; neg = true; } final int years = (int) (months / DateUtility.yearsToMonths); months = months % DateUtility.yearsToMonths; return String.format("%c%03d-%02d", neg ? '-':'+', years, months); }
Example 7
Source File: TimeCalculation.java From mangosta-android with Apache License 2.0 | 5 votes |
private static String getTimeStringAgoSinceDateTime(Context context, DateTime dateTime) { DateTime now = new DateTime(DateTimeZone.getDefault()); Period period = new Period(dateTime, now); String date; int count; if (period.getYears() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_years_ago, period.getYears()); count = period.getYears(); } else if (period.getMonths() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_months_ago, period.getMonths()); count = period.getMonths(); } else if (period.getWeeks() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_weeks_ago, period.getWeeks()); count = period.getWeeks(); } else if (period.getDays() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_days_ago, period.getDays()); count = period.getDays(); } else if (period.getHours() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_hours_ago, period.getHours()); count = period.getHours(); } else if (period.getMinutes() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_minutes_ago, period.getMinutes()); count = period.getMinutes(); } else if (period.getSeconds() >= 3) { date = String.format(Locale.getDefault(), context.getString(R.string.date_seconds_ago), period.getSeconds()); count = period.getSeconds(); } else { return " " + context.getString(R.string.date_seconds_now); } return String.format(Locale.getDefault(), date, count); }
Example 8
Source File: WeeklyWorkLoadDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public WeeklyWorkLoadView(final Interval executionPeriodInterval) { this.executionPeriodInterval = executionPeriodInterval; final Period period = executionPeriodInterval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; intervalTypes = new IntervalType[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = executionPeriodInterval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } }
Example 9
Source File: Grouping.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static DateTime makeOrigin(DateTime first, Period period) { if (period.getYears() > 0) { return first.year().roundFloorCopy().toDateTime(); } else if (period.getMonths() > 0) { return first.monthOfYear().roundFloorCopy().toDateTime(); } else if (period.getWeeks() > 0) { return first.weekOfWeekyear().roundFloorCopy().toDateTime(); } else if (period.getDays() > 0) { return first.dayOfYear().roundFloorCopy().toDateTime(); } else if (period.getHours() > 0) { return first.hourOfDay().roundFloorCopy().toDateTime(); } else if (period.getMinutes() > 0) { return first.minuteOfHour().roundFloorCopy().toDateTime(); } else if (period.getSeconds() > 0) { return first.secondOfMinute().roundFloorCopy().toDateTime(); } else if (period.getMillis() > 0) { return first.millisOfSecond().roundFloorCopy().toDateTime(); } throw new IllegalArgumentException(String.format("Unsupported Period '%s'", period)); }
Example 10
Source File: JGenProg2017_00100_t.java From coming with MIT License | 4 votes |
/** * Factory to create instance from builder. * * @param id the zone id * @param outputID true if the zone id should be output * @param transitions the list of Transition objects * @param tailZone optional zone for getting info beyond precalculated tables */ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transition> transitions, DSTZone tailZone) { int size = transitions.size(); if (size == 0) { throw new IllegalArgumentException(); } long[] trans = new long[size]; int[] wallOffsets = new int[size]; int[] standardOffsets = new int[size]; String[] nameKeys = new String[size]; Transition last = null; for (int i=0; i<size; i++) { Transition tr = transitions.get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } if (tailZone != null) { if (tailZone.iStartRecurrence.getNameKey() .equals(tailZone.iEndRecurrence.getNameKey())) { if (tailZone.iStartRecurrence.getSaveMillis() > 0) { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence.renameAppend("-Summer"), tailZone.iEndRecurrence); } else { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence, tailZone.iEndRecurrence.renameAppend("-Summer")); } } } return new PrecalculatedZone ((outputID ? id : ""), trans, wallOffsets, standardOffsets, nameKeys, tailZone); }
Example 11
Source File: Elixir_0038_t.java From coming with MIT License | 4 votes |
/** * Factory to create instance from builder. * * @param id the zone id * @param outputID true if the zone id should be output * @param transitions the list of Transition objects * @param tailZone optional zone for getting info beyond precalculated tables */ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transition> transitions, DSTZone tailZone) { int size = transitions.size(); if (size == 0) { throw new IllegalArgumentException(); } long[] trans = new long[size]; int[] wallOffsets = new int[size]; int[] standardOffsets = new int[size]; String[] nameKeys = new String[size]; Transition last = null; for (int i=0; i<size; i++) { Transition tr = transitions.get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } if (tailZone != null) { if (tailZone.iStartRecurrence.getNameKey() .equals(tailZone.iEndRecurrence.getNameKey())) { if (tailZone.iStartRecurrence.getSaveMillis() > 0) { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence.renameAppend("-Summer"), tailZone.iEndRecurrence); } else { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence, tailZone.iEndRecurrence.renameAppend("-Summer")); } } } return new PrecalculatedZone ((outputID ? id : ""), trans, wallOffsets, standardOffsets, nameKeys, tailZone); }
Example 12
Source File: jKali_0040_t.java From coming with MIT License | 4 votes |
/** * Factory to create instance from builder. * * @param id the zone id * @param outputID true if the zone id should be output * @param transitions the list of Transition objects * @param tailZone optional zone for getting info beyond precalculated tables */ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transition> transitions, DSTZone tailZone) { int size = transitions.size(); if (size == 0) { throw new IllegalArgumentException(); } long[] trans = new long[size]; int[] wallOffsets = new int[size]; int[] standardOffsets = new int[size]; String[] nameKeys = new String[size]; Transition last = null; for (int i=0; i<size; i++) { Transition tr = transitions.get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } if (tailZone != null) { if (tailZone.iStartRecurrence.getNameKey() .equals(tailZone.iEndRecurrence.getNameKey())) { if (tailZone.iStartRecurrence.getSaveMillis() > 0) { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence.renameAppend("-Summer"), tailZone.iEndRecurrence); } else { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence, tailZone.iEndRecurrence.renameAppend("-Summer")); } } } return new PrecalculatedZone ((outputID ? id : ""), trans, wallOffsets, standardOffsets, nameKeys, tailZone); }
Example 13
Source File: DateUtilities.java From Bats with Apache License 2.0 | 4 votes |
public static int monthsFromPeriod(Period period){ return (period.getYears() * yearsToMonths) + period.getMonths(); }
Example 14
Source File: JGenProg2017_00122_t.java From coming with MIT License | 4 votes |
/** * Factory to create instance from builder. * * @param id the zone id * @param outputID true if the zone id should be output * @param transitions the list of Transition objects * @param tailZone optional zone for getting info beyond precalculated tables */ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transition> transitions, DSTZone tailZone) { int size = transitions.size(); if (size == 0) { throw new IllegalArgumentException(); } long[] trans = new long[size]; int[] wallOffsets = new int[size]; int[] standardOffsets = new int[size]; String[] nameKeys = new String[size]; Transition last = null; for (int i=0; i<size; i++) { Transition tr = transitions.get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } return new PrecalculatedZone ((outputID ? id : ""), trans, wallOffsets, standardOffsets, nameKeys, tailZone); }
Example 15
Source File: Arja_00129_t.java From coming with MIT License | 4 votes |
/** * Factory to create instance from builder. * * @param id the zone id * @param outputID true if the zone id should be output * @param transitions the list of Transition objects * @param tailZone optional zone for getting info beyond precalculated tables */ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transition> transitions, DSTZone tailZone) { int size = transitions.size(); if (size == 0) { throw new IllegalArgumentException(); } long[] trans = new long[size]; int[] wallOffsets = new int[size]; int[] standardOffsets = new int[size]; String[] nameKeys = new String[size]; Transition last = null; for (int i=0; i<size; i++) { Transition tr = transitions.get(i); if (!tr.isTransitionFrom(last)) { throw new IllegalArgumentException(id); } trans[i] = tr.getMillis(); wallOffsets[i] = tr.getWallOffset(); standardOffsets[i] = tr.getStandardOffset(); nameKeys[i] = tr.getNameKey(); last = tr; } // Some timezones (Australia) have the same name key for // summer and winter which messes everything up. Fix it here. String[] zoneNameData = new String[5]; String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings(); for (int j = 0; j < zoneStrings.length; j++) { String[] set = zoneStrings[j]; if (set != null && set.length == 5 && id.equals(set[0])) { zoneNameData = set; } } Chronology chrono = ISOChronology.getInstanceUTC(); for (int i = 0; i < nameKeys.length - 1; i++) { String curNameKey = nameKeys[i]; String nextNameKey = nameKeys[i + 1]; long curOffset = wallOffsets[i]; long nextOffset = wallOffsets[i + 1]; long curStdOffset = standardOffsets[i]; long nextStdOffset = standardOffsets[i + 1]; Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono); if (curOffset != nextOffset && curStdOffset == nextStdOffset && curNameKey.equals(nextNameKey) && p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 && curNameKey.equals(zoneNameData[2]) && curNameKey.equals(zoneNameData[4])) { if (ZoneInfoCompiler.verbose()) { System.out.println("Fixing duplicate name key - " + nextNameKey); System.out.println(" - " + new DateTime(trans[i], chrono) + " - " + new DateTime(trans[i + 1], chrono)); } if (curOffset > nextOffset) { nameKeys[i] = (curNameKey + "-Summer").intern(); } else if (curOffset < nextOffset) { nameKeys[i + 1] = (nextNameKey + "-Summer").intern(); i++; } } } if (tailZone != null) { if (tailZone.iStartRecurrence.getNameKey() .equals(tailZone.iEndRecurrence.getNameKey())) { tailZone=new DSTZone(tailZone.getID(),tailZone.iStandardOffset,tailZone.iStartRecurrence.renameAppend("-Summer"),tailZone.iEndRecurrence); if (tailZone.iStartRecurrence.getSaveMillis() > 0) { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence.renameAppend("-Summer"), tailZone.iEndRecurrence); } else { tailZone = new DSTZone( tailZone.getID(), tailZone.iStandardOffset, tailZone.iStartRecurrence, tailZone.iEndRecurrence.renameAppend("-Summer")); } } } return new PrecalculatedZone ((outputID ? id : ""), trans, wallOffsets, standardOffsets, nameKeys, tailZone); }
Example 16
Source File: DURATION.java From warp10-platform with Apache License 2.0 | 4 votes |
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object o = stack.pop(); if (!(o instanceof String)) { throw new WarpScriptException(getName() + " expects an ISO8601 duration (a string) on top of the stack. See http://en.wikipedia.org/wiki/ISO_8601#Durations"); } // Separate seconds from digits below second precision String duration_string = o.toString(); String[] tokens = UnsafeString.split(duration_string, '.'); long offset = 0; if (tokens.length > 2) { throw new WarpScriptException(getName() + "received an invalid ISO8601 duration."); } if (2 == tokens.length) { duration_string = tokens[0].concat("S"); String tmp = tokens[1].substring(0, tokens[1].length() - 1); Double d_offset = Double.valueOf("0." + tmp) * STU; offset = d_offset.longValue(); } ReadWritablePeriod period = new MutablePeriod(); ISOPeriodFormat.standard().getParser().parseInto(period, duration_string, 0, Locale.US); Period p = period.toPeriod(); if (p.getMonths() != 0 || p.getYears() != 0) { throw new WarpScriptException(getName() + " doesn't support ambiguous durations containing years or months, please convert those to days."); } Duration duration = p.toDurationFrom(new Instant()); // check if offset should be positive of negative if (p.getSeconds() < 0) { offset = -offset; } stack.push(duration.getMillis() * Constants.TIME_UNITS_PER_MS + offset); return stack; }
Example 17
Source File: JodaDateUtility.java From dremio-oss with Apache License 2.0 | 4 votes |
public static int monthsFromPeriod(Period period) { return (period.getYears() * yearsToMonths) + period.getMonths(); }
Example 18
Source File: Fixtures.java From dremio-oss with Apache License 2.0 | 4 votes |
private static Cell toCell(Object obj){ Preconditions.checkNotNull(obj, "Use Null constants to express nulls, such as NULL_VARCHAR, NULL_INT, etc."); if(obj instanceof Cell){ return (Cell) obj; } else if(obj instanceof String){ return new VarChar((String) obj); }else if(obj instanceof Long){ return new BigInt((Long)obj); }else if(obj instanceof Double){ return new DoublePrecision((Double)obj); }else if(obj instanceof Float){ return new Floating((Float)obj); }else if(obj instanceof Integer){ return new IntCell((Integer)obj); }else if(obj instanceof Boolean){ return new BooleanCell((Boolean)obj); }else if(obj instanceof byte[]){ return new VarBinary((byte[])obj); }else if(obj instanceof LocalDateTime) { return new Timestamp((LocalDateTime)obj); }else if(obj instanceof LocalTime) { return new Time((LocalTime)obj); }else if(obj instanceof LocalDate) { return new Date((LocalDate)obj); }else if(obj instanceof List) { return new ListCell((List<Integer>)obj); }else if(obj instanceof BigDecimal) { return new Decimal((BigDecimal) obj); } else if(obj instanceof Period) { Period p = (Period) obj; if (p.getYears() == 0 && p.getMonths() == 0) { return new IntervalDaySecond(p); } if (p.getDays() == 0) { return new IntervalYearMonth(p); } } throw new UnsupportedOperationException(String.format("Unable to interpret object of type %s.", obj.getClass().getSimpleName())); }
Example 19
Source File: DateUtilities.java From Bats with Apache License 2.0 | 4 votes |
public static int periodToMonths(Period value) { return value.getYears() * yearsToMonths + value.getMonths(); }