org.joda.time.chrono.ISOChronology Java Examples

The following examples show how to use org.joda.time.chrono.ISOChronology. 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: DateTimeFunctions.java    From presto with Apache License 2.0 7 votes vote down vote up
private static DateTimeField getDateField(ISOChronology chronology, Slice unit)
{
    String unitString = unit.toStringUtf8().toLowerCase(ENGLISH);
    switch (unitString) {
        case "day":
            return chronology.dayOfMonth();
        case "week":
            return chronology.weekOfWeekyear();
        case "month":
            return chronology.monthOfYear();
        case "quarter":
            return QUARTER_OF_YEAR.getField(chronology);
        case "year":
            return chronology.year();
    }
    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "'" + unitString + "' is not a valid DATE field");
}
 
Example #2
Source File: Time_10_BaseSingleFieldPeriod_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a new instance representing the number of complete standard length units
 * in the specified period.
 * <p>
 * This factory method converts all fields from the period to hours using standardised
 * durations for each field. Only those fields which have a precise duration in
 * the ISO UTC chronology can be converted.
 * <ul>
 * <li>One week consists of 7 days.
 * <li>One day consists of 24 hours.
 * <li>One hour consists of 60 minutes.
 * <li>One minute consists of 60 seconds.
 * <li>One second consists of 1000 milliseconds.
 * </ul>
 * Months and Years are imprecise and periods containing these values cannot be converted.
 *
 * @param period  the period to get the number of hours from, must not be null
 * @param millisPerUnit  the number of milliseconds in one standard unit of this period
 * @throws IllegalArgumentException if the period contains imprecise duration values
 */
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
    if (period == null) {
        return 0;
    }
    Chronology iso = ISOChronology.getInstanceUTC();
    long duration = 0L;
    for (int i = 0; i < period.size(); i++) {
        int value = period.getValue(i);
        if (value != 0) {
            DurationField field = period.getFieldType(i).getField(iso);
            if (field.isPrecise() == false) {
                throw new IllegalArgumentException(
                        "Cannot convert period to duration as " + field.getName() +
                        " is not precise in the period " + period);
            }
            duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
        }
    }
    return FieldUtils.safeToInt(duration / millisPerUnit);
}
 
Example #3
Source File: TestChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testEqualsHashCode_Strict() {
    Chronology chrono1 = StrictChronology.getInstance(ISOChronology.getInstanceUTC());
    Chronology chrono2 = StrictChronology.getInstance(ISOChronology.getInstanceUTC());
    Chronology chrono3 = StrictChronology.getInstance(ISOChronology.getInstance());
    
    assertEquals(true, chrono1.equals(chrono2));
    assertEquals(false, chrono1.equals(chrono3));
    
    DateTime dt1 = new DateTime(0L, chrono1);
    DateTime dt2 = new DateTime(0L, chrono2);
    DateTime dt3 = new DateTime(0L, chrono3);
    
    assertEquals(true, dt1.equals(dt2));
    assertEquals(false, dt1.equals(dt3));
    
    assertEquals(true, chrono1.hashCode() == chrono2.hashCode());
    assertEquals(false, chrono1.hashCode() == chrono3.hashCode());
}
 
Example #4
Source File: jKali_0051_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #5
Source File: TestMutableDateTime_Basics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testToMutableDateTime_Chronology() {
    MutableDateTime test = new MutableDateTime(TEST_TIME1);
    MutableDateTime result = test.toMutableDateTime(ISOChronology.getInstance());
    assertTrue(test != result);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISOChronology.getInstance(), result.getChronology());

    test = new MutableDateTime(TEST_TIME1);
    result = test.toMutableDateTime(GregorianChronology.getInstance(PARIS));
    assertTrue(test != result);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(GregorianChronology.getInstance(PARIS), result.getChronology());

    test = new MutableDateTime(TEST_TIME1, GregorianChronology.getInstance(PARIS));
    result = test.toMutableDateTime((Chronology) null);
    assertTrue(test != result);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISOChronology.getInstance(), result.getChronology());

    test = new MutableDateTime(TEST_TIME1);
    result = test.toMutableDateTime((Chronology) null);
    assertTrue(test != result);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISOChronology.getInstance(), result.getChronology());
}
 
Example #6
Source File: TestMutableDateTime_Basics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testGetMethods() {
    MutableDateTime test = new MutableDateTime();
    
    assertEquals(ISOChronology.getInstance(), test.getChronology());
    assertEquals(LONDON, test.getZone());
    assertEquals(TEST_TIME_NOW, test.getMillis());
    
    assertEquals(1, test.getEra());
    assertEquals(20, test.getCenturyOfEra());
    assertEquals(2, test.getYearOfCentury());
    assertEquals(2002, test.getYearOfEra());
    assertEquals(2002, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(2002, test.getWeekyear());
    assertEquals(23, test.getWeekOfWeekyear());
    assertEquals(7, test.getDayOfWeek());
    assertEquals(160, test.getDayOfYear());
    assertEquals(1, test.getHourOfDay());
    assertEquals(0, test.getMinuteOfHour());
    assertEquals(60, test.getMinuteOfDay());
    assertEquals(0, test.getSecondOfMinute());
    assertEquals(60 * 60, test.getSecondOfDay());
    assertEquals(0, test.getMillisOfSecond());
    assertEquals(60 * 60 * 1000, test.getMillisOfDay());
}
 
Example #7
Source File: DateTimeFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
public static DateTimeField getTimestampField(ISOChronology chronology, Slice unit)
{
    String unitString = unit.toStringUtf8().toLowerCase(ENGLISH);
    switch (unitString) {
        case "millisecond":
            return chronology.millisOfSecond();
        case "second":
            return chronology.secondOfMinute();
        case "minute":
            return chronology.minuteOfHour();
        case "hour":
            return chronology.hourOfDay();
        case "day":
            return chronology.dayOfMonth();
        case "week":
            return chronology.weekOfWeekyear();
        case "month":
            return chronology.monthOfYear();
        case "quarter":
            return QUARTER_OF_YEAR.getField(chronology);
        case "year":
            return chronology.year();
    }
    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "'" + unitString + "' is not a valid Timestamp field");
}
 
Example #8
Source File: jMutRepair_0045_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #9
Source File: Nopol2017_0085_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #10
Source File: Arja_0087_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #11
Source File: Cardumen_00238_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #12
Source File: Tasks.java    From heroic with Apache License 2.0 6 votes vote down vote up
public static long parseInstant(String input, long now) {
    if (input.charAt(0) == '+') {
        return now + Long.parseLong(input.substring(1));
    }

    if (input.charAt(0) == '-') {
        return now - Long.parseLong(input.substring(1));
    }

    // try to parse just milliseconds
    try {
        return Long.parseLong(input);
    } catch (IllegalArgumentException e) {
        // pass-through
    }

    final Chronology chrono = ISOChronology.getInstanceUTC();

    if (input.indexOf('/') >= 0) {
        return parseFullInstant(input, chrono);
    }

    return parseTodayInstant(input, chrono, now);
}
 
Example #13
Source File: jMutRepair_0029_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #14
Source File: Arja_00110_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param standardOffset standard offset just before instant
 */
public long setInstant(int year, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    Chronology chrono = ISOChronology.getInstanceUTC();
    long millis = chrono.year().set(0, year);
    millis = chrono.monthOfYear().set(millis, iMonthOfYear);
    millis = chrono.millisOfDay().set(millis, iMillisOfDay);
    millis = setDayOfMonth(chrono, millis);

    if (iDayOfWeek != 0) {
        millis = setDayOfWeek(chrono, millis);
    }

    // Convert from local time to UTC.
    return millis - offset;
}
 
Example #15
Source File: TestDateTimeUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testGetInstantChronology_RI() {
    DateTime dt = new DateTime(123L, BuddhistChronology.getInstance());
    assertEquals(BuddhistChronology.getInstance(), DateTimeUtils.getInstantChronology(dt));
    
    Instant i = new Instant(123L);
    assertEquals(ISOChronology.getInstanceUTC(), DateTimeUtils.getInstantChronology(i));
    
    AbstractInstant ai = new AbstractInstant() {
        public long getMillis() {
            return 0L;
        }
        public Chronology getChronology() {
            return null; // testing for this
        }
    };
    assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(ai));
    
    assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(null));
}
 
Example #16
Source File: TestMutableInterval_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testConstructor_RP_RI4() throws Throwable {
    DateTime dt = new DateTime(TEST_TIME_NOW);
    Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().hours().add(result, -1);
    result = ISOChronology.getInstance().millis().add(result, -23);
    
    MutableInterval test = new MutableInterval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
}
 
Example #17
Source File: DruidDateTimeUtils.java    From calcite with Apache License 2.0 5 votes vote down vote up
protected static List<Interval> toInterval(
    List<Range<Long>> ranges) {
  List<Interval> intervals = Lists.transform(ranges, range -> {
    if (!range.hasLowerBound() && !range.hasUpperBound()) {
      return DruidTable.DEFAULT_INTERVAL;
    }
    long start = range.hasLowerBound()
        ? range.lowerEndpoint().longValue()
        : DruidTable.DEFAULT_INTERVAL.getStartMillis();
    long end = range.hasUpperBound()
        ? range.upperEndpoint().longValue()
        : DruidTable.DEFAULT_INTERVAL.getEndMillis();
    if (range.hasLowerBound()
        && range.lowerBoundType() == BoundType.OPEN) {
      start++;
    }
    if (range.hasUpperBound()
        && range.upperBoundType() == BoundType.CLOSED) {
      end++;
    }
    return new Interval(start, end, ISOChronology.getInstanceUTC());
  });
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Converted time ranges " + ranges + " to interval " + intervals);
  }
  return intervals;
}
 
Example #18
Source File: TestTextFields.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testHalfdayNames() {
    DateTimeFormatter printer = DateTimeFormat.forPattern("a");
    for (int i=0; i<ZONES.length; i++) {
        Chronology chrono = ISOChronology.getInstance(ZONES[i]);
        MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
        for (int hour=0; hour<24; hour++) {
            mdt.setHourOfDay(hour);
            int halfday = mdt.get(chrono.halfdayOfDay());
            String halfdayText = printer.print(mdt);
            assertEquals(HALFDAYS[halfday], halfdayText);
        }
    }
}
 
Example #19
Source File: TestReadableIntervalConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSetIntoInterval_Object4() throws Exception {
    MutableInterval i = new MutableInterval(0L, 123L) {
        public Chronology getChronology() {
            return null; // bad
        }
    };
    MutableInterval m = new MutableInterval(-1000L, 1000L, BuddhistChronology.getInstance());
    ReadableIntervalConverter.INSTANCE.setInto(m, i, null);
    assertEquals(0L, m.getStartMillis());
    assertEquals(123L, m.getEndMillis());
    assertEquals(ISOChronology.getInstance(), m.getChronology());
}
 
Example #20
Source File: PersianCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int isoWeekday( DateTimeUnit dateTimeUnit )
{

    DateTime dateTime = toIso( dateTimeUnit )
        .toJodaDateTime( ISOChronology.getInstance( DateTimeZone.getDefault() ) );
    return dateTime.getDayOfWeek();
}
 
Example #21
Source File: JGenProg2017_0076_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * @param standardOffset standard offset just before previous recurrence
 */
public long previous(long instant, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    // Convert from UTC to local time.
    instant += offset;

    Chronology chrono = ISOChronology.getInstanceUTC();
    long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
    // Be lenient with millisOfDay.
    prev = chrono.millisOfDay().set(prev, 0);
    prev = chrono.millisOfDay().add(prev, iMillisOfDay);
    prev = setDayOfMonthPrevious(chrono, prev);

    if (iDayOfWeek == 0) {
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = setDayOfMonthPrevious(chrono, prev);
        }
    } else {
        prev = setDayOfWeek(chrono, prev);
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = chrono.monthOfYear().set(prev, iMonthOfYear);
            prev = setDayOfMonthPrevious(chrono, prev);
            prev = setDayOfWeek(chrono, prev);
        }
    }

    // Convert from local time to UTC.
    return prev - offset;
}
 
Example #22
Source File: Arja_00146_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * @param standardOffset standard offset just before previous recurrence
 */
public long previous(long instant, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    // Convert from UTC to local time.
    instant += offset;

    Chronology chrono = ISOChronology.getInstanceUTC();
    long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
    // Be lenient with millisOfDay.
    prev = chrono.millisOfDay().set(prev, 0);
    prev = chrono.millisOfDay().add(prev, iMillisOfDay);
    prev = setDayOfMonthPrevious(chrono, prev);

    if (iDayOfWeek == 0) {
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = setDayOfMonthPrevious(chrono, prev);
        }
    } else {
        prev = setDayOfWeek(chrono, prev);
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = chrono.monthOfYear().set(prev, iMonthOfYear);
            prev = setDayOfMonthPrevious(chrono, prev);
            prev = setDayOfWeek(chrono, prev);
        }
    }

    // Convert from local time to UTC.
    return prev - offset;
}
 
Example #23
Source File: Arja_0048_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @param standardOffset standard offset just before previous recurrence
 */
public long previous(long instant, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    // Convert from UTC to local time.
    instant += offset;

    Chronology chrono = ISOChronology.getInstanceUTC();
    long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
    // Be lenient with millisOfDay.
    prev = chrono.millisOfDay().set(prev, 0);
    prev = chrono.millisOfDay().add(prev, iMillisOfDay);
    prev = setDayOfMonthPrevious(chrono, prev);

    if (iDayOfWeek == 0) {
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = setDayOfMonthPrevious(chrono, prev);
        }
    } else {
        prev = setDayOfWeek(chrono, prev);
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = chrono.monthOfYear().set(prev, iMonthOfYear);
            prev = setDayOfMonthPrevious(chrono, prev);
            prev = setDayOfWeek(chrono, prev);
        }
    }

    // Convert from local time to UTC.
    return prev - offset;
}
 
Example #24
Source File: LastDayOfMonth.java    From presto with Apache License 2.0 5 votes vote down vote up
private static long lastDayOfMonth(ISOChronology chronology, long millis)
{
    // Calculate point in time corresponding to midnight (00:00) of first day of next month in the given zone.
    millis = chronology.monthOfYear().roundCeiling(millis + 1);
    // Convert to UTC and take the previous day
    millis = chronology.getZone().convertUTCToLocal(millis) - MILLISECONDS_IN_DAY;
    return MILLISECONDS.toDays(millis);
}
 
Example #25
Source File: JGenProg2017_00141_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @param standardOffset standard offset just before previous recurrence
 */
public long previous(long instant, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    // Convert from UTC to local time.
    instant += offset;

    Chronology chrono = ISOChronology.getInstanceUTC();
    long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
    // Be lenient with millisOfDay.
    prev = chrono.millisOfDay().set(prev, 0);
    prev = chrono.millisOfDay().add(prev, iMillisOfDay);
    prev = setDayOfMonthPrevious(chrono, prev);

    if (iDayOfWeek == 0) {
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = setDayOfMonthPrevious(chrono, prev);
        }
    } else {
        prev = setDayOfWeek(chrono, prev);
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = chrono.monthOfYear().set(prev, iMonthOfYear);
            prev = setDayOfMonthPrevious(chrono, prev);
            prev = setDayOfWeek(chrono, prev);
        }
    }

    // Convert from local time to UTC.
    return prev - offset;
}
 
Example #26
Source File: TestReadableDurationConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    JULIAN = JulianChronology.getInstance();
    ISO = ISOChronology.getInstance();
    zone = DateTimeZone.getDefault();
    DateTimeZone.setDefault(PARIS);
}
 
Example #27
Source File: jMutRepair_0029_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @param standardOffset standard offset just before previous recurrence
 */
public long previous(long instant, int standardOffset, int saveMillis) {
    int offset;
    if (iMode == 'w') {
        offset = standardOffset + saveMillis;
    } else if (iMode == 's') {
        offset = standardOffset;
    } else {
        offset = 0;
    }

    // Convert from UTC to local time.
    instant += offset;

    Chronology chrono = ISOChronology.getInstanceUTC();
    long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
    // Be lenient with millisOfDay.
    prev = chrono.millisOfDay().set(prev, 0);
    prev = chrono.millisOfDay().add(prev, iMillisOfDay);
    prev = setDayOfMonthPrevious(chrono, prev);

    if (iDayOfWeek == 0) {
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = setDayOfMonthPrevious(chrono, prev);
        }
    } else {
        prev = setDayOfWeek(chrono, prev);
        if (prev >= instant) {
            prev = chrono.year().add(prev, -1);
            prev = chrono.monthOfYear().set(prev, iMonthOfYear);
            prev = setDayOfMonthPrevious(chrono, prev);
            prev = setDayOfWeek(chrono, prev);
        }
    }

    // Convert from local time to UTC.
    return prev - offset;
}
 
Example #28
Source File: FormatDateTime.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Slice format(ConnectorSession session, long epochMillis, ISOChronology chronology, Slice formatString)
{
    try {
        return utf8Slice(DateTimeFormat.forPattern(formatString.toStringUtf8())
                .withChronology(chronology)
                .withLocale(session.getLocale())
                .print(epochMillis));
    }
    catch (Exception e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
    }
}
 
Example #29
Source File: LogoutRequestUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    LogoutRequest req = (LogoutRequest) samlObject;

    if (attribute.getLocalName().equals(LogoutRequest.REASON_ATTRIB_NAME)) {
        req.setReason(attribute.getValue());
    } else if (attribute.getLocalName().equals(LogoutRequest.NOT_ON_OR_AFTER_ATTRIB_NAME)
            && !DatatypeHelper.isEmpty(attribute.getValue())) {
        req.setNotOnOrAfter(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
 
Example #30
Source File: TestStringConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSetIntoInterval_Object_Chronology4() throws Exception {
    MutableInterval m = new MutableInterval(-1000L, 1000L);
    StringConverter.INSTANCE.setInto(m, "2004-06-09T+06:00/P1Y2M", null);
    assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getStart());
    assertEquals(new DateTime(2005, 8, 9, 0, 0, 0, 0, SIX).withChronology(null), m.getEnd());
    assertEquals(ISOChronology.getInstance(), m.getChronology());
}