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