Search in sources :

Example 71 with LocalDateTime

use of org.joda.time.LocalDateTime in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindDateTimeWithSpecificStyle.

@Test
public void testBindDateTimeWithSpecificStyle() throws Exception {
    JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
    registrar.setDateTimeStyle("MM");
    setUp(registrar);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTime", new LocalDateTime(2009, 10, 31, 12, 0));
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
    assertTrue(value.startsWith("Oct 31, 2009"));
    assertTrue(value.endsWith("12:00:00 PM"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 72 with LocalDateTime

use of org.joda.time.LocalDateTime in project head by mifos.

the class LoginServiceFacadeWebTier method changePassword.

@Override
public void changePassword(ChangePasswordRequest changePasswordRequest) {
    PersonnelBO user = this.personnelDao.findPersonnelByUsername(changePasswordRequest.getUsername());
    this.personnelService.changePassword(user, changePasswordRequest.getNewPassword(), true);
    Date newExpirationDate = null;
    if (user.getPasswordExpirationDate() != null) {
        newExpirationDate = new LocalDateTime().plusDays(PasswordRules.getPasswordExpirationDatePrelongation()).toDateTime().toDate();
    }
    personnelService.changePasswordExpirationDate(user, newExpirationDate);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 73 with LocalDateTime

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

the class TestDateTimeFormatterBuilder method test_localPrintParseOffsetAndZone.

public void test_localPrintParseOffsetAndZone() {
    DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm ").appendTimeZoneOffset("Z", true, 2, 2).appendLiteral(' ').appendTimeZoneId();
    DateTimeFormatter f = bld.toFormatter();
    DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, TOKYO);
    assertEquals("2007-03-04 12:30 +09:00 Asia/Tokyo", f.print(dt));
    LocalDateTime expected = new LocalDateTime(2007, 3, 4, 12, 30);
    assertEquals(expected, f.withZone(TOKYO).parseLocalDateTime("2007-03-04 12:30 +09:00 Asia/Tokyo"));
    assertEquals(expected, f.withZone(PARIS).parseLocalDateTime("2007-03-04 12:30 +09:00 Asia/Tokyo"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 74 with LocalDateTime

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

the class DateTimeFormatter method parseLocalDateTime.

/**
     * Parses only the local date-time from the given text, returning a new LocalDateTime.
     * <p>
     * This will parse the text fully according to the formatter, using the UTC zone.
     * Once parsed, only the local date-time will be used.
     * This means that any parsed time-zone or offset field is completely ignored.
     * It also means that the zone and offset-parsed settings are ignored.
     *
     * @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
     * @since 2.0
     */
public LocalDateTime parseLocalDateTime(String text) {
    InternalParser parser = requireParser();
    // always use UTC, avoiding DST gaps
    Chronology chrono = selectChronology(null).withUTC();
    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 (bucket.getOffsetInteger() != null) {
                // treat withOffsetParsed() as being true
                int parsedOffset = bucket.getOffsetInteger();
                DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
                chrono = chrono.withZone(parsedZone);
            } else if (bucket.getZone() != null) {
                chrono = chrono.withZone(bucket.getZone());
            }
            return new LocalDateTime(millis, chrono);
        }
    } else {
        newPos = ~newPos;
    }
    throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Chronology(org.joda.time.Chronology) DateTimeZone(org.joda.time.DateTimeZone)

Example 75 with LocalDateTime

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

the class TestDateTimeFormatter method testParseLocalDateTime_simple.

//-----------------------------------------------------------------------
public void testParseLocalDateTime_simple() {
    assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30Z"));
    assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30+18:00"));
    assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30-18:00"));
    assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30, 0, BUDDHIST_PARIS), g.withChronology(BUDDHIST_PARIS).parseLocalDateTime("2004-06-09T10:20:30Z"));
    try {
        g.parseDateTime("ABC");
        fail();
    } catch (IllegalArgumentException ex) {
    }
}
Also used : LocalDateTime(org.joda.time.LocalDateTime)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4