use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestLenientChronology method test_setDayOfMonth.
//-----------------------------------------------------------------------
public void test_setDayOfMonth() {
Chronology zone = LenientChronology.getInstance(ISOChronology.getInstanceUTC());
DateTime dt = new DateTime(2007, 1, 1, 0, 0, 0, 0, zone);
assertEquals("2007-01-01T00:00:00.000Z", dt.toString());
dt = dt.withDayOfMonth(32);
assertEquals("2007-02-01T00:00:00.000Z", dt.toString());
dt = dt.withDayOfMonth(0);
assertEquals("2007-01-31T00:00:00.000Z", dt.toString());
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestLenientChronology method test_setHourOfDay.
//-----------------------------------------------------------------------
public void test_setHourOfDay() {
Chronology zone = LenientChronology.getInstance(ISOChronology.getInstanceUTC());
DateTime dt = new DateTime(2007, 1, 1, 0, 0, 0, 0, zone);
assertEquals("2007-01-01T00:00:00.000Z", dt.toString());
dt = dt.withHourOfDay(24);
assertEquals("2007-01-02T00:00:00.000Z", dt.toString());
dt = dt.withHourOfDay(-1);
assertEquals("2007-01-01T23:00:00.000Z", dt.toString());
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestLenientChronology method test_setMonthOfYear.
//-----------------------------------------------------------------------
public void test_setMonthOfYear() {
Chronology zone = LenientChronology.getInstance(ISOChronology.getInstanceUTC());
DateTime dt = new DateTime(2007, 1, 1, 0, 0, 0, 0, zone);
assertEquals("2007-01-01T00:00:00.000Z", dt.toString());
dt = dt.withMonthOfYear(13);
assertEquals("2008-01-01T00:00:00.000Z", dt.toString());
dt = dt.withMonthOfYear(0);
assertEquals("2007-12-01T00:00:00.000Z", dt.toString());
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestGregorianChronology method testLeap_28feb.
public void testLeap_28feb() {
Chronology chrono = GregorianChronology.getInstance();
DateTime dt = new DateTime(2012, 2, 28, 0, 0, chrono);
assertEquals(true, dt.year().isLeap());
assertEquals(true, dt.monthOfYear().isLeap());
assertEquals(false, dt.dayOfMonth().isLeap());
assertEquals(false, dt.dayOfYear().isLeap());
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class DateTimeFormatter method parseDateTime.
/**
* Parses a date-time from the given text, returning a new DateTime.
* <p>
* The parse will use the zone and chronology specified on this formatter.
* <p>
* If the text contains a time zone string then that will be taken into
* account in adjusting the time of day as follows.
* If the {@link #withOffsetParsed()} has been called, then the resulting
* DateTime will have a fixed offset based on the parsed time zone.
* Otherwise the resulting DateTime will have the zone of this formatter,
* but the parsed zone may have caused the time to be adjusted.
*
* @param text the text to parse, not null
* @return the parsed date-time, never null
* @throws UnsupportedOperationException if parsing is not supported
* @throws IllegalArgumentException if the text to parse is invalid
*/
public DateTime parseDateTime(String text) {
InternalParser parser = requireParser();
Chronology chrono = selectChronology(null);
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
int newPos = parser.parseInto(bucket, text, 0);
if (newPos >= 0) {
if (newPos >= text.length()) {
long millis = bucket.computeMillis(true, text);
if (iOffsetParsed && bucket.getOffsetInteger() != null) {
int parsedOffset = bucket.getOffsetInteger();
DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
chrono = chrono.withZone(parsedZone);
} else if (bucket.getZone() != null) {
chrono = chrono.withZone(bucket.getZone());
}
DateTime dt = new DateTime(millis, chrono);
if (iZone != null) {
dt = dt.withZone(iZone);
}
return dt;
}
} else {
newPos = ~newPos;
}
throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
Aggregations