List of usage examples for org.joda.time Chronology minuteOfHour
public abstract DateTimeField minuteOfHour();
From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java
License:Apache License
private DateTimeField timeUnitToTimeField(final TimeUnit timeUnit) { final Chronology chronology = GregorianChronology.getInstance(_timeZone); switch (timeUnit) { case YEARS:/*ww w. j a va2s .co m*/ return chronology.year(); case MONTHS: return chronology.monthOfYear(); case WEEKS: return chronology.weekOfWeekyear(); case DAYS: return chronology.dayOfMonth(); case HOURS: return chronology.hourOfDay(); case MINUTES: return chronology.minuteOfHour(); case SECONDS: return chronology.secondOfDay(); default: return chronology.millisOfSecond(); } }
From source file:net.sourceforge.fenixedu.util.HourMinuteSecond.java
License:Open Source License
/** * Gets the field for a specific index in the chronology specified. * <p>// w w w.j a v a 2 s. co m * This method must not use any instance variables. * * @param index * the index to retrieve * @param chrono * the chronology to use * @return the field */ @Override protected DateTimeField getField(int index, Chronology chrono) { switch (index) { case HOUR_OF_DAY: return chrono.hourOfDay(); case MINUTE_OF_HOUR: return chrono.minuteOfHour(); case SECOND_OF_MINUTE: return chrono.secondOfMinute(); default: throw new IndexOutOfBoundsException("Invalid index: " + index); } }
From source file:org.jruby.ext.date.RubyDateTime.java
License:LGPL
@JRubyMethod(name = "civil", alias = "new", meta = true, optional = 8) public static RubyDateTime civil(ThreadContext context, IRubyObject self, IRubyObject[] args) { // year=-4712, month=1, mday=1, // hour=0, minute=0, second=0, offset=0, start=Date::ITALY final int len = args.length; int hour = 0, minute = 0, second = 0; long millis = 0; long subMillisNum = 0, subMillisDen = 1; int off = 0;//w ww .java 2 s . c om long sg = ITALY; if (len == 8) sg = val2sg(context, args[7]); if (len >= 7) off = val2off(context, args[6]); final int year = (sg > 0) ? getYear(args[0]) : args[0].convertToInteger().getIntValue(); final int month = getMonth(args[1]); final long[] rest = new long[] { 0, 1 }; final int day = (int) getDay(context, args[2], rest); if (len >= 4 || rest[0] != 0) { hour = getHour(context, len >= 4 ? args[3] : RubyFixnum.zero(context.runtime), rest); } if (len >= 5 || rest[0] != 0) { minute = getMinute(context, len >= 5 ? args[4] : RubyFixnum.zero(context.runtime), rest); } if (len >= 6 || rest[0] != 0) { IRubyObject sec = len >= 6 ? args[5] : RubyFixnum.zero(context.runtime); second = getSecond(context, sec, rest); final long r0 = rest[0], r1 = rest[1]; if (r0 != 0) { millis = (1000 * r0) / r1; subMillisNum = ((1000 * r0) - (millis * r1)); subMillisDen = r1; } } if (hour == 24 && (minute != 0 || second != 0 || millis != 0)) { throw context.runtime.newArgumentError("invalid date"); } final Chronology chronology = getChronology(context, sg, off); DateTime dt = civilDate(context, year, month, day, chronology); // hour: 0, minute: 0, second: 0 try { long ms = dt.getMillis(); ms = chronology.hourOfDay().set(ms, hour == 24 ? 0 : hour); ms = chronology.minuteOfHour().set(ms, minute); ms = chronology.secondOfMinute().set(ms, second); dt = dt.withMillis(ms + millis); if (hour == 24) dt = dt.plusDays(1); } catch (IllegalArgumentException ex) { debug(context, "invalid date", ex); throw context.runtime.newArgumentError("invalid date"); } return (RubyDateTime) new RubyDateTime(context.runtime, (RubyClass) self, dt, off, sg, subMillisNum, subMillisDen).normalizeSubMillis(); }