Search in sources :

Example 26 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestDateTimeFormatter method testParseLocalDate_yearOfEra.

public void testParseLocalDate_yearOfEra() {
    Chronology chrono = GJChronology.getInstanceUTC();
    DateTimeFormatter f = DateTimeFormat.forPattern("YYYY-MM GG").withChronology(chrono).withLocale(Locale.UK);
    LocalDate date = new LocalDate(2005, 10, 1, chrono);
    assertEquals(date, f.parseLocalDate("2005-10 AD"));
    assertEquals(date, f.parseLocalDate("2005-10 CE"));
    date = new LocalDate(-2005, 10, 1, chrono);
    assertEquals(date, f.parseLocalDate("2005-10 BC"));
    assertEquals(date, f.parseLocalDate("2005-10 BCE"));
}
Also used : Chronology(org.joda.time.Chronology) GJChronology(org.joda.time.chrono.GJChronology) ISOChronology(org.joda.time.chrono.ISOChronology) BuddhistChronology(org.joda.time.chrono.BuddhistChronology) LocalDate(org.joda.time.LocalDate)

Example 27 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class ReadableInstantConverter method getChronology.

//-----------------------------------------------------------------------
/**
     * Gets the chronology, which is taken from the ReadableInstant.
     * If the chronology on the instant is null, the ISOChronology in the
     * specified time zone is used.
     * If the chronology on the instant is not in the specified zone, it is
     * adapted.
     * 
     * @param object  the ReadableInstant to convert, must not be null
     * @param zone  the specified zone to use, null means default zone
     * @return the chronology, never null
     */
public Chronology getChronology(Object object, DateTimeZone zone) {
    Chronology chrono = ((ReadableInstant) object).getChronology();
    if (chrono == null) {
        return ISOChronology.getInstance(zone);
    }
    DateTimeZone chronoZone = chrono.getZone();
    if (chronoZone != zone) {
        chrono = chrono.withZone(zone);
        if (chrono == null) {
            return ISOChronology.getInstance(zone);
        }
    }
    return chrono;
}
Also used : ReadableInstant(org.joda.time.ReadableInstant) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) DateTimeZone(org.joda.time.DateTimeZone)

Example 28 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class AbstractInstant method toDateTime.

/**
     * Get this object as a DateTime using the same chronology but a different zone.
     * 
     * @param zone time zone to apply, or default if null
     * @return a DateTime using the same millis
     */
public DateTime toDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new DateTime(getMillis(), chrono);
}
Also used : Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Example 29 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class AbstractInstant method toMutableDateTime.

/**
     * Get this object as a MutableDateTime using the same chronology but a different zone.
     * 
     * @param zone time zone to apply, or default if null
     * @return a MutableDateTime using the same millis
     */
public MutableDateTime toMutableDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new MutableDateTime(getMillis(), chrono);
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology)

Example 30 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class AbstractPartial method toDateTime.

//-----------------------------------------------------------------------
/**
     * Resolves this partial against another complete instant to create a new
     * full instant. The combination is performed using the chronology of the
     * specified instant.
     * <p>
     * For example, if this partial represents a time, then the result of this
     * method will be the datetime from the specified base instant plus the
     * time from this partial.
     *
     * @param baseInstant  the instant that provides the missing fields, null means now
     * @return the combined datetime
     */
public DateTime toDateTime(ReadableInstant baseInstant) {
    Chronology chrono = DateTimeUtils.getInstantChronology(baseInstant);
    long instantMillis = DateTimeUtils.getInstantMillis(baseInstant);
    long resolved = chrono.set(this, instantMillis);
    return new DateTime(resolved, chrono);
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Aggregations

Chronology (org.joda.time.Chronology)69 DateTime (org.joda.time.DateTime)32 ISOChronology (org.joda.time.chrono.ISOChronology)30 GJChronology (org.joda.time.chrono.GJChronology)18 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)17 LocalDate (org.joda.time.LocalDate)14 DateTimeZone (org.joda.time.DateTimeZone)13 MutableDateTime (org.joda.time.MutableDateTime)7 LocalDateTime (org.joda.time.LocalDateTime)4 ReadableDateTime (org.joda.time.ReadableDateTime)4 JulianChronology (org.joda.time.chrono.JulianChronology)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Serializable (java.io.Serializable)2 Date (java.util.Date)2 Duration (org.joda.time.Duration)2 Period (org.joda.time.Period)2 ReadableDuration (org.joda.time.ReadableDuration)2 ReadableInstant (org.joda.time.ReadableInstant)2 ReadablePartial (org.joda.time.ReadablePartial)2 Calendar (java.util.Calendar)1