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"));
}
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;
}
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);
}
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);
}
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);
}
Aggregations