本文整理汇总了Java中org.joda.time.DateMidnight.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DateMidnight.parse方法的具体用法?Java DateMidnight.parse怎么用?Java DateMidnight.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateMidnight
的用法示例。
在下文中一共展示了DateMidnight.parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FilterPeriod
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
public FilterPeriod(Optional<String> startDateAsString, Optional<String> endDateAsString) {
Assert.notNull(startDateAsString, "Start date must be given");
Assert.notNull(endDateAsString, "End date must be given");
// Set default values for dates
int currentYear = DateMidnight.now().getYear();
this.startDate = DateUtil.getFirstDayOfYear(currentYear);
this.endDate = DateUtil.getLastDayOfYear(currentYear);
// Override default values with parsed dates
DateTimeFormatter formatter = DateTimeFormat.forPattern(DateFormat.PATTERN);
if (startDateAsString.isPresent()) {
this.startDate = DateMidnight.parse(startDateAsString.get(), formatter);
}
if (endDateAsString.isPresent()) {
this.endDate = DateMidnight.parse(endDateAsString.get(), formatter);
}
Assert.isTrue(endDate.isAfter(startDate) || endDate.isEqual(startDate), "Start date must be before end date");
}
示例2: assertVacationOverviewsForExistingDepartment
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@Test
public void assertVacationOverviewsForExistingDepartment() throws Exception {
Department department = new Department();
String departmentName = "Admins";
department.setName(departmentName);
String email = "[email protected]";
Person person = new Person("test", "Muster", "Max", email);
department.setMembers(Arrays.asList(person));
DateMidnight testDate = DateMidnight.parse("2017-09-01");
FederalState federalState = FederalState.BADEN_WUERTTEMBERG;
when(departmentService.getAllDepartments()).thenReturn(Arrays.asList(department));
when(workingTimeService.getFederalStateForPerson(eq(person), any(DateMidnight.class))).thenReturn(federalState);
when(publicHolidayService.getWorkingDurationOfDate(any(DateMidnight.class), any(FederalState.class))).thenReturn(DayLength.FULL.getDuration());
List<VacationOverview> vacationOverviews =
sut.getVacationOverviews(departmentName, testDate.getYear(), testDate.getMonthOfYear());
assertThat(vacationOverviews, hasSize(1));
assertThat(vacationOverviews.get(0).getPerson().getEmail(), is(email));
assertThat(vacationOverviews.get(0).getDays().get(0).getTypeOfDay(), is(WORKDAY));
}
示例3: convertToObject
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
/**
* Attempts to convert a String to a Date object. Pre-processes the input by invoking the method preProcessInput(), then uses an ordered
* list of DateFormat objects (supplied by getDateFormats()) to try and parse the String into a Date.
*/
@Override
public DateMidnight convertToObject(final String value, final Locale locale)
{
if (StringUtils.isBlank(value) == true) {
return null;
}
final String[] formatStrings = getFormatStrings(locale);
final DateTimeFormatter[] dateFormats = new DateTimeFormatter[formatStrings.length];
for (int i = 0; i < formatStrings.length; i++) {
dateFormats[i] = getDateTimeFormatter(formatStrings[i], locale);
}
DateMidnight date = null;
for (final DateTimeFormatter formatter : dateFormats) {
try {
date = DateMidnight.parse(value, formatter);
break;
} catch (final Exception ex) { /* Do nothing, we'll get lots of these. */
if (log.isDebugEnabled() == true) {
log.debug(ex.getMessage(), ex);
}
}
}
// If we successfully parsed, return a date, otherwise send back an error
if (date != null) {
return date;
} else {
log.info("Unparseable date string (user's input): " + value);
throw new ConversionException("validation.error.general"); // Message key will not be used (dummy).
}
}
示例4: workDays
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
/**
* Calculate number of work days for the given period and person.
*
* @param from start date as String (e.g. 2013-3-21)
* @param to end date as String (e.g. 2013-3-21)
* @param length day length as String (FULL, MORNING or NOON)
* @param personId id of the person to number of work days for
*
* @return number of days as String for the given parameters or "N/A" if parameters are not valid in any way
*/
@ApiOperation(
value = "Calculate the work days for a certain period and person",
notes = "The calculation depends on the working time of the person."
)
@RequestMapping(value = "/workdays", method = RequestMethod.GET)
public ResponseWrapper<WorkDayResponse> workDays(
@ApiParam(value = "Start date with pattern yyyy-MM-dd", defaultValue = "2016-01-01")
@RequestParam("from")
String from,
@ApiParam(value = "End date with pattern yyyy-MM-dd", defaultValue = "2016-01-08")
@RequestParam("to")
String to,
@ApiParam(value = "Day Length", defaultValue = "FULL", allowableValues = "FULL, MORNING, NOON")
@RequestParam("length")
String length,
@ApiParam(value = "ID of the person")
@RequestParam("person")
Integer personId) {
DateTimeFormatter fmt = DateTimeFormat.forPattern(RestApiDateFormat.DATE_PATTERN);
DateMidnight startDate = DateMidnight.parse(from, fmt);
DateMidnight endDate = DateMidnight.parse(to, fmt);
if (startDate.isAfter(endDate)) {
throw new IllegalArgumentException("Parameter 'from' must be before or equals to 'to' parameter");
}
Optional<Person> person = personService.getPersonByID(personId);
if (!person.isPresent()) {
throw new IllegalArgumentException("No person found for ID=" + personId);
}
DayLength howLong = DayLength.valueOf(length);
BigDecimal days = workDaysService.getWorkDays(howLong, startDate, endDate, person.get());
return new ResponseWrapper<>(new WorkDayResponse(days.toString()));
}
示例5: personsAvailabilities
import org.joda.time.DateMidnight; //导入方法依赖的package包/类
@ApiOperation(
value = "Get all availabilities for a certain period and person",
notes =
"Get all availabilities for a certain period and person. Maximum allowed period per request is one month."
)
@RequestMapping(value = "/availabilities", method = RequestMethod.GET)
public AvailabilityList personsAvailabilities(
@ApiParam(value = "start of interval to get availabilities from (inclusive)", defaultValue = "2016-01-01")
@RequestParam("from")
String startDateString,
@ApiParam(value = "end of interval to get availabilities from (inclusive)", defaultValue = "2016-01-31")
@RequestParam("to")
String endDateString,
@ApiParam(value = "login name of the person")
@RequestParam(value = "person")
String personLoginName) {
Optional<Person> optionalPerson = personService.getPersonByLogin(personLoginName);
if (!optionalPerson.isPresent()) {
throw new IllegalArgumentException("No person found for loginName = " + personLoginName);
}
DateMidnight startDate = DateMidnight.parse(startDateString);
DateMidnight endDate = DateMidnight.parse(endDateString);
if (startDate.isAfter(endDate)) {
throw new IllegalArgumentException("startdate " + startDateString + " must not be after endDate "
+ endDateString);
}
boolean requestedDateRangeIsMoreThanOneMonth = startDate.minusDays(1).isBefore(endDate.minusMonths(1));
if (requestedDateRangeIsMoreThanOneMonth) {
throw new IllegalArgumentException("Requested date range to large. Maximum allowed range is one month");
}
return availabilityService.getPersonsAvailabilities(startDate, endDate, optionalPerson.get());
}