Java Code Examples for org.joda.time.DateTimeZone#previousTransition()

The following examples show how to use org.joda.time.DateTimeZone#previousTransition() . 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: TestBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
static void testReverseTransitions(DateTimeZone tz, String[][] data) {
    long instant = new DateTime(data[data.length - 1][0]).getMillis();
    for (int i=data.length; --i>=1; ) {
        String[] row = data[i];
        String[] prevRow = data[i - 1];
        instant = tz.previousTransition(instant);

        long expectedInstant = new DateTime(row[0]).getMillis() - 1;
        String expectedKey = prevRow[1];
        int expectedStandardOffset = -(int) OFFSET_FORMATTER.parseMillis(prevRow[2]);
        int expectedOffset = -(int) OFFSET_FORMATTER.parseMillis(prevRow[3]);

        assertEquals(expectedInstant, instant);
        assertEquals(expectedKey, tz.getNameKey(instant));
        assertEquals(expectedStandardOffset, tz.getStandardOffset(instant));
        assertEquals(expectedOffset, tz.getOffset(instant));
    }
}
 
Example 2
Source File: TestBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
static void testReverseTransitions(DateTimeZone tz, String[][] data) {
    long instant = new DateTime(data[data.length - 1][0]).getMillis();
    for (int i=data.length; --i>=1; ) {
        String[] row = data[i];
        String[] prevRow = data[i - 1];
        instant = tz.previousTransition(instant);

        long expectedInstant = new DateTime(row[0]).getMillis() - 1;
        String expectedKey = prevRow[1];
        int expectedStandardOffset = -(int) OFFSET_FORMATTER.parseMillis(prevRow[2]);
        int expectedOffset = -(int) OFFSET_FORMATTER.parseMillis(prevRow[3]);

        assertEquals(expectedInstant, instant);
        assertEquals(expectedKey, tz.getNameKey(instant));
        assertEquals(expectedStandardOffset, tz.getStandardOffset(instant));
        assertEquals(expectedOffset, tz.getOffset(instant));
    }
}
 
Example 3
Source File: Time_11_ZoneInfoCompiler_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @return false if error.
 */
static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
        return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
        long next = tz.nextTransition(millis);
        if (next == millis || next > end) {
            break;
        }

        millis = next;

        int nextOffset = tz.getOffset(millis);
        String nextKey = tz.getNameKey(millis);

        if (offset == nextOffset
            && key.equals(nextKey)) {
            System.out.println("*d* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()));
            return false;
        }

        if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
            System.out.println("*s* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC())
                               + ", nameKey=" + nextKey);
            return false;
        }

        transitions.add(Long.valueOf(millis));

        offset = nextOffset;
        key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i=transitions.size(); --i>= 0; ) {
        long prev = tz.previousTransition(millis);
        if (prev == millis || prev < end) {
            break;
        }

        millis = prev;

        long trans = transitions.get(i).longValue();
        
        if (trans - 1 != millis) {
            System.out.println("*r* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()) + " != "
                               + new DateTime(trans - 1,
                                              ISOChronology.getInstanceUTC()));
                               
            return false;
        }
    }

    return true;
}
 
Example 4
Source File: Time_11_ZoneInfoCompiler_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @return false if error.
 */
static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
        return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
        long next = tz.nextTransition(millis);
        if (next == millis || next > end) {
            break;
        }

        millis = next;

        int nextOffset = tz.getOffset(millis);
        String nextKey = tz.getNameKey(millis);

        if (offset == nextOffset
            && key.equals(nextKey)) {
            System.out.println("*d* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()));
            return false;
        }

        if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
            System.out.println("*s* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC())
                               + ", nameKey=" + nextKey);
            return false;
        }

        transitions.add(Long.valueOf(millis));

        offset = nextOffset;
        key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i=transitions.size(); --i>= 0; ) {
        long prev = tz.previousTransition(millis);
        if (prev == millis || prev < end) {
            break;
        }

        millis = prev;

        long trans = transitions.get(i).longValue();
        
        if (trans - 1 != millis) {
            System.out.println("*r* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()) + " != "
                               + new DateTime(trans - 1,
                                              ISOChronology.getInstanceUTC()));
                               
            return false;
        }
    }

    return true;
}
 
Example 5
Source File: ZoneInfoCompiler.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return false if error.
 */
static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
        return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
        long next = tz.nextTransition(millis);
        if (next == millis || next > end) {
            break;
        }

        millis = next;

        int nextOffset = tz.getOffset(millis);
        String nextKey = tz.getNameKey(millis);

        if (offset == nextOffset
            && key.equals(nextKey)) {
            System.out.println("*d* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()));
            return false;
        }

        if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
            System.out.println("*s* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC())
                               + ", nameKey=" + nextKey);
            return false;
        }

        transitions.add(Long.valueOf(millis));

        offset = nextOffset;
        key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i=transitions.size(); --i>= 0; ) {
        long prev = tz.previousTransition(millis);
        if (prev == millis || prev < end) {
            break;
        }

        millis = prev;

        long trans = transitions.get(i).longValue();
        
        if (trans - 1 != millis) {
            System.out.println("*r* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()) + " != "
                               + new DateTime(trans - 1,
                                              ISOChronology.getInstanceUTC()));
                               
            return false;
        }
    }

    return true;
}
 
Example 6
Source File: ZoneInfoCompiler.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return false if error.
 */
static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
        return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
        long next = tz.nextTransition(millis);
        if (next == millis || next > end) {
            break;
        }

        millis = next;

        int nextOffset = tz.getOffset(millis);
        String nextKey = tz.getNameKey(millis);

        if (offset == nextOffset
            && key.equals(nextKey)) {
            System.out.println("*d* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()));
            return false;
        }

        if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
            System.out.println("*s* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC())
                               + ", nameKey=" + nextKey);
            return false;
        }

        transitions.add(Long.valueOf(millis));

        offset = nextOffset;
        key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i=transitions.size(); --i>= 0; ) {
        long prev = tz.previousTransition(millis);
        if (prev == millis || prev < end) {
            break;
        }

        millis = prev;

        long trans = transitions.get(i).longValue();
        
        if (trans - 1 != millis) {
            System.out.println("*r* Error in " + tz.getID() + " "
                               + new DateTime(millis,
                                              ISOChronology.getInstanceUTC()) + " != "
                               + new DateTime(trans - 1,
                                              ISOChronology.getInstanceUTC()));
                               
            return false;
        }
    }

    return true;
}