Java Code Examples for org.joda.time.chrono.ISOChronology#getInstanceUTC()

The following examples show how to use org.joda.time.chrono.ISOChronology#getInstanceUTC() . 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: 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 2
Source File: TestPeriod_Constructors.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testConstructor_long_Chronology2() throws Throwable {
    long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
            5 * DateTimeConstants.MILLIS_PER_HOUR +
            6 * DateTimeConstants.MILLIS_PER_MINUTE +
            7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
    Period test = new Period(length, ISOChronology.getInstanceUTC());
    assertEquals(PeriodType.standard(), test.getPeriodType());
    assertEquals(0, test.getYears());
    assertEquals(0, test.getMonths());
    assertEquals(0, test.getWeeks());
    assertEquals(4, test.getDays());
    assertEquals(5, test.getHours());
    assertEquals(6, test.getMinutes());
    assertEquals(7, test.getSeconds());
    assertEquals(8, test.getMillis());
}
 
Example 3
Source File: JGenProg2017_00122_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 4
Source File: Nopol2017_0085_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 5
Source File: Time_12_LocalDate_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Handle broken serialization from other tools.
 * @return the resolved object, not null
 */
private Object readResolve() {
    if (iChronology == null) {
        return new LocalDate(iLocalMillis, ISOChronology.getInstanceUTC());
    }
    if (DateTimeZone.UTC.equals(iChronology.getZone()) == false) {
        return new LocalDate(iLocalMillis, iChronology.withUTC());
    }
    return this;
}
 
Example 6
Source File: TestAbstractPartial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ReadablePartial getReadablePartial() {
    return new MockPartial() {
        public Chronology getChronology() {
            return ISOChronology.getInstanceUTC();
        }
    };
}
 
Example 7
Source File: AvroKryoSerializerUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, LocalDate localDate) {
	output.writeInt(localDate.getYear());
	output.writeInt(localDate.getMonthOfYear());
	output.writeInt(localDate.getDayOfMonth());

	final Chronology chronology = localDate.getChronology();
	if (chronology != null && chronology != ISOChronology.getInstanceUTC()) {
		throw new RuntimeException("Unsupported chronology: " + chronology);
	}
}
 
Example 8
Source File: ExtractMillisecond.java    From presto with Apache License 2.0 5 votes vote down vote up
@LiteralParameters("p")
@SqlType(StandardTypes.BIGINT)
public static long extract(@LiteralParameter("p") long precision, ConnectorSession session, @SqlType("timestamp(p)") long timestamp)
{
    if (precision > 3) {
        timestamp = scaleEpochMicrosToMillis(timestamp);
    }

    ISOChronology chronology = ISOChronology.getInstanceUTC();
    if (session.isLegacyTimestamp()) {
        chronology = getChronology(session.getTimeZoneKey());
    }

    return chronology.millisOfSecond().get(timestamp);
}
 
Example 9
Source File: JGenProg2017_00122_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 10
Source File: Arja_0048_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 11
Source File: TestMutableInterval_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testConstructor_RP_RI3() throws Throwable {
    DateTime dt = new DateTime(TEST_TIME_NOW, ISOChronology.getInstanceUTC());
    Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstanceUTC().months().add(result, -6);
    result = ISOChronology.getInstanceUTC().days().add(result, -3);
    result = ISOChronology.getInstanceUTC().hours().add(result, -1);
    
    MutableInterval test = new MutableInterval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
}
 
Example 12
Source File: jMutRepair_0045_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 13
Source File: ExtractDayOfYear.java    From presto with Apache License 2.0 5 votes vote down vote up
@LiteralParameters("p")
@SqlType(StandardTypes.BIGINT)
public static long extract(@LiteralParameter("p") long precision, ConnectorSession session, @SqlType("timestamp(p)") long timestamp)
{
    if (precision > 3) {
        timestamp = scaleEpochMicrosToMillis(timestamp);
    }

    ISOChronology chronology = ISOChronology.getInstanceUTC();
    if (session.isLegacyTimestamp()) {
        chronology = getChronology(session.getTimeZoneKey());
    }

    return chronology.dayOfYear().get(timestamp);
}
 
Example 14
Source File: JGenProg2017_0076_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 15
Source File: TestMonthDay_Basics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testMinusMonths_int_fromLeap() {
    MonthDay test = new MonthDay(2, 29, ISOChronology.getInstanceUTC());
    MonthDay result = test.minusMonths(1);
    MonthDay expected = new MonthDay(1, 29, ISOChronology.getInstance());
    assertEquals(expected, result);
}
 
Example 16
Source File: JGenProg2017_00122_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * 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 17
Source File: DateUtils.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
public static String toUtc(String date){
	DateTime datetime=new DateTime(date, ISOChronology.getInstanceUTC());
	return datetime.toString();
}
 
Example 18
Source File: TestMonthDay_Basics.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testPlusDays_int_negativeFromLeap() {
    MonthDay test = new MonthDay(2, 29, ISOChronology.getInstanceUTC());
    MonthDay result = test.plusDays(-1);
    MonthDay expected = new MonthDay(2, 28, ISOChronology.getInstance());
    assertEquals(expected, result);
}
 
Example 19
Source File: Time_12_LocalDateTime_t.java    From coming with MIT License 3 votes vote down vote up
/**
 * Constructs an instance set to the specified date and time
 * using <code>ISOChronology</code>.
 *
 * @param year  the year
 * @param monthOfYear  the month of the year, from 1 to 12
 * @param dayOfMonth  the day of the month, from 1 to 31
 * @param hourOfDay  the hour of the day, from 0 to 23
 * @param minuteOfHour  the minute of the hour, from 0 to 59
 * @param secondOfMinute  the second of the minute, from 0 to 59
 * @param millisOfSecond  the millisecond of the second, from 0 to 999
 */
public LocalDateTime(
        int year,
        int monthOfYear,
        int dayOfMonth,
        int hourOfDay,
        int minuteOfHour,
        int secondOfMinute,
        int millisOfSecond) {
    this(year, monthOfYear, dayOfMonth, hourOfDay,
        minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstanceUTC());
}
 
Example 20
Source File: LocalTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an instance set to the specified time
 * using <code>ISOChronology</code>.
 *
 * @param hourOfDay  the hour of the day, from 0 to 23
 * @param minuteOfHour  the minute of the hour, from 0 to 59
 * @param secondOfMinute  the second of the minute, from 0 to 59
 */
public LocalTime(
        int hourOfDay,
        int minuteOfHour,
        int secondOfMinute) {
    this(hourOfDay, minuteOfHour, secondOfMinute, 0, ISOChronology.getInstanceUTC());
}