Example usage for org.joda.time LocalDate getYearOfCentury

List of usage examples for org.joda.time LocalDate getYearOfCentury

Introduction

In this page you can find the example usage for org.joda.time LocalDate getYearOfCentury.

Prototype

public int getYearOfCentury() 

Source Link

Document

Get the year of century field value.

Usage

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void seekField(Granulaarsus field, int direction, int soughtValue, boolean excludingCurrent) {
    // ---------------------------------
    //  DAY_OF_MONTH
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_MONTH && direction != 0 && soughtValue == 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
        ajaFookus = nihutatudFookus;//from ww  w.  ja v a 2s.c o  m
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  DAY_OF_WEEK
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_WEEK && soughtValue >= DateTimeConstants.MONDAY
            && soughtValue <= DateTimeConstants.SUNDAY && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne p2ev ehk p2ev, millest tahame tingimata m66duda
        int algneNadalapaev = (excludingCurrent) ? (ajaFookus.getDayOfWeek()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadalapaev = ajaFookus.getDayOfWeek();
            if (algneNadalapaev != -1) {
                if (algneNadalapaev == uusNadalapaev) {
                    continue;
                } else {
                    algneNadalapaev = -1;
                }
            }
            if (uusNadalapaev == soughtValue) {
                algneNadalapaev = uusNadalapaev;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  WEEK OF YEAR
    // ---------------------------------
    if (field == Granulaarsus.WEEK_OF_YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne n2dal ehk n2dal, millest tahame m88duda
        int algneNadal = (excludingCurrent) ? (ajaFookus.getWeekOfWeekyear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadal = nihutatudFookus.getWeekOfWeekyear();
            if (algneNadal != -1) {
                if (algneNadal == uusNadal) {
                    continue;
                } else {
                    algneNadal = -1;
                }
            }
            if (soughtValue == 0) {
                algneNadal = uusNadal;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.WEEK_OF_YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  MONTH
    // ---------------------------------
    if (field == Granulaarsus.MONTH
            && (soughtValue == 0
                    || DateTimeConstants.JANUARY <= soughtValue && soughtValue <= DateTimeConstants.DECEMBER)
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne kuu ehk kuu, millest tahame m88duda
        int algneKuu = (excludingCurrent) ? (ajaFookus.getMonthOfYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusKuu = nihutatudFookus.getMonthOfYear();
            if (algneKuu != -1) {
                if (algneKuu == uusKuu) {
                    continue;
                } else {
                    algneKuu = -1;
                }
            }
            if (soughtValue == 0 || (soughtValue != 0 && uusKuu == soughtValue)) {
                algneKuu = uusKuu;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR
    // ---------------------------------
    if (field == Granulaarsus.YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne aasta ehk aasta, millest tahame m88duda
        int algneAasta = (excludingCurrent) ? (ajaFookus.getYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusAasta = nihutatudFookus.getYear();
            if (algneAasta != -1) {
                if (algneAasta == uusAasta) {
                    continue;
                } else {
                    algneAasta = -1;
                }
            }
            if (soughtValue == 0) {
                algneAasta = uusAasta;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR_OF_CENTURY
    // ---------------------------------
    if (field == Granulaarsus.YEAR_OF_CENTURY && direction != 0) {
        int minValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), false);
        int maxValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), true);
        if (minValue <= soughtValue && soughtValue <= maxValue) {
            int dir = (direction > 0) ? (1) : (-1);
            LocalDate ajaFookus = new LocalDate(this.underlyingDate);
            // Algne aasta ehk aasta, millest tahame m88duda
            int algneAasta = (excludingCurrent) ? (ajaFookus.getYearOfCentury()) : (-1);
            if (!excludingCurrent) {
                // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
                ajaFookus = ajaFookus.plusYears(dir * (-1));
            }
            int count = 0;
            int cycleCount = 0;
            while (true) {
                LocalDate nihutatudFookus = ajaFookus.plusYears(1 * dir);
                cycleCount++;
                ajaFookus = nihutatudFookus;
                int uusAasta = nihutatudFookus.getYearOfCentury();
                if (algneAasta != -1) {
                    if (algneAasta == uusAasta) {
                        continue;
                    } else {
                        algneAasta = -1;
                    }
                }
                if (uusAasta == soughtValue) {
                    algneAasta = uusAasta;
                    count++;
                    if (count == Math.abs(direction)) {
                        break;
                    }
                }
            }
            this.underlyingDate = ajaFookus;
            updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
            this.dateModified = true;
        }
    }
    // ---------------------------------
    //   CENTURY_OF_ERA
    // ---------------------------------
    if (field == Granulaarsus.CENTURY_OF_ERA && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne saj ehk sajand, millest tahame m88duda
        int algneSajand = (excludingCurrent) ? (ajaFookus.getCenturyOfEra()) : (Integer.MIN_VALUE);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
            ajaFookus = ajaFookus.plusYears(dir * (-10));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusYears(10 * dir);
            ajaFookus = nihutatudFookus;
            int uusSajand = nihutatudFookus.getCenturyOfEra();
            if (algneSajand != Integer.MIN_VALUE) {
                if (algneSajand == uusSajand) {
                    continue;
                } else {
                    algneSajand = Integer.MIN_VALUE;
                }
            }
            if (soughtValue == 0) {
                algneSajand = uusSajand;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.CENTURY_OF_ERA, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }

}