int gjYearFromFixed(long date) {
        long d0 = date - 1;
        long n400 = div(d0, 146097);
        long d1 = mod(d0, 146097);
        long n100 = div(d1, 36524);
        long d2 = mod(d1, 36524);
        long n4 = div(d2, 1461);
        long d3 = mod(d2, 1461);
        long n1 = div(d3, 365);
        long year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
        if (!(n100 == 4 || n1 == 4)) {
            year += 1;
        }

        int year_i = (int)year;
        if (year_i == year) {
            return year_i;
        } else {
            throw new RuntimeException("year cannot be cast to an int: " + year);
        }
    }