Java Code Examples for org.joda.time.DateTimeUtils#getZone()

The following examples show how to use org.joda.time.DateTimeUtils#getZone() . 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: Time_18_GJChronology_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
    }

    GJChronology chrono;

    ArrayList<GJChronology> chronos = cCache.get(zone);
    if (chronos == null) {
        chronos = new ArrayList<GJChronology>(2);
        cCache.put(zone, chronos);
    } else {
        for (int i=chronos.size(); --i>=0; ) {
            chrono = chronos.get(i);
            if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                cutoverInstant.equals(chrono.getGregorianCutover())) {
                
                return chrono;
            }
        }
    }

    if (zone == DateTimeZone.UTC) {
        chrono = new GJChronology
            (JulianChronology.getInstance(zone, minDaysInFirstWeek),
             GregorianChronology.getInstance(zone, minDaysInFirstWeek),
             cutoverInstant);
    } else {
        chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
        chrono = new GJChronology
            (ZonedChronology.getInstance(chrono, zone),
             chrono.iJulianChronology,
             chrono.iGregorianChronology,
             chrono.iCutoverInstant);
    }

    chronos.add(chrono);

    return chrono;
}
 
Example 2
Source File: Time_18_GJChronology_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
    }

    GJChronology chrono;

    ArrayList<GJChronology> chronos = cCache.get(zone);
    if (chronos == null) {
        chronos = new ArrayList<GJChronology>(2);
        cCache.put(zone, chronos);
    } else {
        for (int i=chronos.size(); --i>=0; ) {
            chrono = chronos.get(i);
            if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                cutoverInstant.equals(chrono.getGregorianCutover())) {
                
                return chrono;
            }
        }
    }

    if (zone == DateTimeZone.UTC) {
        chrono = new GJChronology
            (JulianChronology.getInstance(zone, minDaysInFirstWeek),
             GregorianChronology.getInstance(zone, minDaysInFirstWeek),
             cutoverInstant);
    } else {
        chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
        chrono = new GJChronology
            (ZonedChronology.getInstance(chrono, zone),
             chrono.iJulianChronology,
             chrono.iGregorianChronology,
             chrono.iCutoverInstant);
    }

    chronos.add(chrono);

    return chrono;
}
 
Example 3
Source File: Time_6_GJChronology_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
    }

    GJChronology chrono;
    synchronized (cCache) {
        ArrayList<GJChronology> chronos = cCache.get(zone);
        if (chronos == null) {
            chronos = new ArrayList<GJChronology>(2);
            cCache.put(zone, chronos);
        } else {
            for (int i = chronos.size(); --i >= 0;) {
                chrono = chronos.get(i);
                if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                    cutoverInstant.equals(chrono.getGregorianCutover())) {
                    
                    return chrono;
                }
            }
        }
        if (zone == DateTimeZone.UTC) {
            chrono = new GJChronology
                (JulianChronology.getInstance(zone, minDaysInFirstWeek),
                 GregorianChronology.getInstance(zone, minDaysInFirstWeek),
                 cutoverInstant);
        } else {
            chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
            chrono = new GJChronology
                (ZonedChronology.getInstance(chrono, zone),
                 chrono.iJulianChronology,
                 chrono.iGregorianChronology,
                 chrono.iCutoverInstant);
        }
        chronos.add(chrono);
    }
    return chrono;
}
 
Example 4
Source File: Time_6_GJChronology_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
        LocalDate cutoverDate = new LocalDate(cutoverInstant.getMillis(), GregorianChronology.getInstance(zone));
        if (cutoverDate.getYear() <= 0) {
            throw new IllegalArgumentException("Cutover too early. Must be on or after 0001-01-01.");
        }
    }

    GJChronology chrono;
    synchronized (cCache) {
        ArrayList<GJChronology> chronos = cCache.get(zone);
        if (chronos == null) {
            chronos = new ArrayList<GJChronology>(2);
            cCache.put(zone, chronos);
        } else {
            for (int i = chronos.size(); --i >= 0;) {
                chrono = chronos.get(i);
                if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                    cutoverInstant.equals(chrono.getGregorianCutover())) {
                    
                    return chrono;
                }
            }
        }
        if (zone == DateTimeZone.UTC) {
            chrono = new GJChronology
                (JulianChronology.getInstance(zone, minDaysInFirstWeek),
                 GregorianChronology.getInstance(zone, minDaysInFirstWeek),
                 cutoverInstant);
        } else {
            chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
            chrono = new GJChronology
                (ZonedChronology.getInstance(chrono, zone),
                 chrono.iJulianChronology,
                 chrono.iGregorianChronology,
                 chrono.iCutoverInstant);
        }
        chronos.add(chrono);
    }
    return chrono;
}
 
Example 5
Source File: GJChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
        LocalDate cutoverDate = new LocalDate(cutoverInstant.getMillis(), GregorianChronology.getInstance(zone));
        if (cutoverDate.getYear() <= 0) {
            throw new IllegalArgumentException("Cutover too early. Must be on or after 0001-01-01.");
        }
    }

    GJChronology chrono;
    synchronized (cCache) {
        ArrayList<GJChronology> chronos = cCache.get(zone);
        if (chronos == null) {
            chronos = new ArrayList<GJChronology>(2);
            cCache.put(zone, chronos);
        } else {
            for (int i = chronos.size(); --i >= 0;) {
                chrono = chronos.get(i);
                if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                    cutoverInstant.equals(chrono.getGregorianCutover())) {
                    
                    return chrono;
                }
            }
        }
        if (zone == DateTimeZone.UTC) {
            chrono = new GJChronology
                (JulianChronology.getInstance(zone, minDaysInFirstWeek),
                 GregorianChronology.getInstance(zone, minDaysInFirstWeek),
                 cutoverInstant);
        } else {
            chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
            chrono = new GJChronology
                (ZonedChronology.getInstance(chrono, zone),
                 chrono.iJulianChronology,
                 chrono.iGregorianChronology,
                 chrono.iCutoverInstant);
        }
        chronos.add(chrono);
    }
    return chrono;
}
 
Example 6
Source File: GJChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Factory method returns instances of the GJ cutover chronology. Any
 * cutover date may be specified.
 *
 * @param zone  the time zone to use, null is default
 * @param gregorianCutover  the cutover to use, null means default
 * @param minDaysInFirstWeek  minimum number of days in first week of the year; default is 4
 */
public static synchronized GJChronology getInstance(
        DateTimeZone zone,
        ReadableInstant gregorianCutover,
        int minDaysInFirstWeek) {
    
    zone = DateTimeUtils.getZone(zone);
    Instant cutoverInstant;
    if (gregorianCutover == null) {
        cutoverInstant = DEFAULT_CUTOVER;
    } else {
        cutoverInstant = gregorianCutover.toInstant();
    }

    GJChronology chrono;

    ArrayList<GJChronology> chronos = cCache.get(zone);
    if (chronos == null) {
        chronos = new ArrayList<GJChronology>(2);
        cCache.put(zone, chronos);
    } else {
        for (int i=chronos.size(); --i>=0; ) {
            chrono = chronos.get(i);
            if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
                cutoverInstant.equals(chrono.getGregorianCutover())) {
                
                return chrono;
            }
        }
    }

    if (zone == DateTimeZone.UTC) {
        chrono = new GJChronology
            (JulianChronology.getInstance(zone, minDaysInFirstWeek),
             GregorianChronology.getInstance(zone, minDaysInFirstWeek),
             cutoverInstant);
    } else {
        chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
        chrono = new GJChronology
            (ZonedChronology.getInstance(chrono, zone),
             chrono.iJulianChronology,
             chrono.iGregorianChronology,
             chrono.iCutoverInstant);
    }

    chronos.add(chrono);

    return chrono;
}
 
Example 7
Source File: HourMinuteSecond.java    From fenixedu-academic with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Converts this object to an Interval representing the whole day.
 * 
 * @param zone
 *            the zone to get the Interval in, null means default
 * @return a interval over the day
 */
public Interval toInterval(DateTimeZone zone) {
    zone = DateTimeUtils.getZone(zone);
    return toDateMidnight(zone).toInterval();
}