Search in sources :

Example 41 with Chronology

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());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 42 with Chronology

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());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 43 with Chronology

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());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 44 with Chronology

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());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 45 with Chronology

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));
}
Also used : Chronology(org.joda.time.Chronology) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) MutableDateTime(org.joda.time.MutableDateTime)

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