本文整理匯總了Java中org.joda.time.LocalDate類的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate類的具體用法?Java LocalDate怎麽用?Java LocalDate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LocalDate類屬於org.joda.time包,在下文中一共展示了LocalDate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dateValidWithServiceResponseAsync
import org.joda.time.LocalDate; //導入依賴的package包/類
/**
* Get '2012-01-01' as date.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> dateValidWithServiceResponseAsync() {
final LocalDate datePath = LocalDate.parse("2012-01-01");
return service.dateValid(datePath)
.flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = dateValidDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
示例2: getWeekIncludeThisDay
import org.joda.time.LocalDate; //導入依賴的package包/類
public static CalendarWeek getWeekIncludeThisDay(LocalDate localDate) {
LocalDate monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate tuesday = localDate.withDayOfWeek(DateTimeConstants.TUESDAY);
LocalDate wednesday = localDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);
LocalDate thursday = localDate.withDayOfWeek(DateTimeConstants.THURSDAY);
LocalDate friday = localDate.withDayOfWeek(DateTimeConstants.FRIDAY);
LocalDate saturday = localDate.withDayOfWeek(DateTimeConstants.SATURDAY);
LocalDate sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY);
CalendarWeek calendarWeek = new CalendarWeek(
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
);
calendarWeek.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
calendarWeek.originDate = localDate;
return calendarWeek;
}
示例3: getMonthIncludeThisDay
import org.joda.time.LocalDate; //導入依賴的package包/類
public static CalendarMonth getMonthIncludeThisDay(LocalDate localDate) {
CalendarMonth calendarMonth = new CalendarMonth();
calendarMonth.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
for (int i = 0; i < 6; i++) {//每個月最多6周,最少4周
CalendarWeek w = getWeekIncludeThisDay(calendarMonth.firstDayOfCurrentMonth.plusDays(7 * i));
if (i < 4) {
calendarMonth.calendarWeeks.addLast(w);
} else if (w.calendarDayList.getFirst().day.getMonthOfYear() == calendarMonth.firstDayOfCurrentMonth.getMonthOfYear()) {
/**
* 從第5周開始檢
* 如果w的第一天的月份等於本月第一天的月份,那麽這一周也算本月的周
*/
calendarMonth.calendarWeeks.addLast(w);
} else {
break;
}
}
calendarMonth.originDate = localDate;
return calendarMonth;
}
示例4: RequestRequestBuilder
import org.joda.time.LocalDate; //導入依賴的package包/類
private RequestRequestBuilder(
UUID id,
String requestType,
DateTime requestDate,
UUID itemId,
UUID requesterId,
String fulfilmentPreference,
UUID deliveryAddressTypeId,
LocalDate requestExpirationDate,
LocalDate holdShelfExpirationDate,
ItemSummary itemSummary,
PatronSummary requesterSummary) {
this.id = id;
this.requestType = requestType;
this.requestDate = requestDate;
this.itemId = itemId;
this.requesterId = requesterId;
this.fulfilmentPreference = fulfilmentPreference;
this.deliveryAddressTypeId = deliveryAddressTypeId;
this.requestExpirationDate = requestExpirationDate;
this.holdShelfExpirationDate = holdShelfExpirationDate;
this.itemSummary = itemSummary;
this.requesterSummary = requesterSummary;
}
示例5: createDefaultAdapter
import org.joda.time.LocalDate; //導入依賴的package包/類
public void createDefaultAdapter() {
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
.registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
.create();
okBuilder = new OkHttpClient.Builder();
String baseUrl = "https://api.us-east-1.mbedcloud.com";
if(!baseUrl.endsWith("/"))
baseUrl = baseUrl + "/";
adapterBuilder = new Retrofit
.Builder()
.baseUrl(baseUrl)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonCustomConverterFactory.create(gson));
}
示例6: dailyMenusMonthlyMonthyearGet
import org.joda.time.LocalDate; //導入依賴的package包/類
/**
* @return a list to the chef, of Daily Menus of month & year he wants
*/
@PreAuthorize("hasAuthority('chef')")
public List<DailyMenuChef> dailyMenusMonthlyMonthyearGet(String monthyear) throws ApiException
{
String patternString = "^\\d{2}-\\d{4}$";
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(patternString);
Matcher matcher = pattern.matcher(monthyear);
if (matcher.matches())
{
LocalDate monthYearDate = new LocalDate().withYear(Integer.parseInt(monthyear.substring(3, 7))).withMonthOfYear(Integer.parseInt(monthyear.substring(0, 2)));
LocalDate startOfMonth = monthYearDate.dayOfMonth().withMinimumValue();
int daysOfMonth = monthYearDate.dayOfMonth().withMaximumValue().getDayOfMonth();
List<DailyMenuChef> monthlyMenu = new ArrayList<>();
for (int i = 0; i < daysOfMonth; i++)
{
if (getDailyMenuChef(startOfMonth).getDate() != null)
monthlyMenu.add(getDailyMenuChef(startOfMonth));
startOfMonth = startOfMonth.plusDays(1);
}
return monthlyMenu;
}
else
throw new ApiException(400, "Invalid date");
}
示例7: recordValueToJavaType
import org.joda.time.LocalDate; //導入依賴的package包/類
/**
* Take a string value retrieved from a {@link Record} and convert it to a java value of the specified
* type.
*
* @param stringValue The value retrieved from a {@link Record}.
* @param type The Java class to use for the result.
* @param <T> The Java type corresponding to the supplied Class
* @return The typed java value.
*/
@SuppressWarnings("unchecked")
public static <T> T recordValueToJavaType(String stringValue, Class<T> type) {
if (type == Integer.class) {
return (T)Integer.valueOf(stringValue);
} else if (type == Long.class) {
return (T)Long.valueOf(stringValue);
} else if (type == Boolean.class) {
return (T)Boolean.valueOf(stringValue);
} else if (type == LocalDate.class) {
return (T)LocalDate.parse(stringValue, FROM_YYYY_MM_DD);
} else if (type == Double.class) {
return (T)Double.valueOf(stringValue);
} else {
return (T)stringValue;
}
}
示例8: getRoomOpeningHours
import org.joda.time.LocalDate; //導入依賴的package包/類
@SubjectNotPresent
public Result getRoomOpeningHours(Long roomId, Optional<String> date) {
if (!date.isPresent()) {
return badRequest("no search date given");
}
LocalDate searchDate = ISODateTimeFormat.dateParser().parseLocalDate(date.get());
PathProperties pp = PathProperties.parse("(*, defaultWorkingHours(*), calendarExceptionEvents(*))");
Query<ExamRoom> query = Ebean.find(ExamRoom.class);
pp.apply(query);
ExamRoom room = query.where().idEq(roomId).findUnique();
if (room == null) {
return notFound("room not found");
}
room.setCalendarExceptionEvents(room.getCalendarExceptionEvents().stream().filter(ee -> {
LocalDate start = new LocalDate(ee.getStartDate()).withDayOfMonth(1);
LocalDate end = new LocalDate(ee.getEndDate()).dayOfMonth().withMaximumValue();
return !start.isAfter(searchDate) && !end.isBefore(searchDate);
}).collect(Collectors.toList()));
return ok(room, pp);
}
示例9: dateNullWithServiceResponseAsync
import org.joda.time.LocalDate; //導入依賴的package包/類
/**
* Get null as date - this should throw or be unusable on the client side, depending on date representation.
*
* @param datePath null as date (should throw)
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> dateNullWithServiceResponseAsync(LocalDate datePath) {
if (datePath == null) {
throw new IllegalArgumentException("Parameter datePath is required and cannot be null.");
}
return service.dateNull(datePath)
.flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = dateNullDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
示例10: getTotalExpense
import org.joda.time.LocalDate; //導入依賴的package包/類
public double getTotalExpense(LocalDate start, LocalDate end) {
List<MoneyItem> l = daoSession.getMoneyItemDao().queryBuilder().where(MoneyItemDao.Properties.Amount.lt(0)).where(MoneyItemDao.Properties.Date.between(start.toDate(), end.toDate())).list();
double total = 0.0;
ListIterator<MoneyItem> listIterator = l.listIterator();
while (listIterator.hasNext()) {
total += listIterator.next().getAmount();
}
return total;
}
示例11: getSlots
import org.joda.time.LocalDate; //導入依賴的package包/類
@Restrict({@Group("ADMIN"), @Group("STUDENT")})
public Result getSlots(Long examId, Long roomId, String day, Collection<Integer> aids) {
User user = getLoggedUser();
Exam exam = getEnrolledExam(examId, user);
if (exam == null) {
return forbidden("sitnet_error_enrolment_not_found");
}
ExamRoom room = Ebean.find(ExamRoom.class, roomId);
if (room == null) {
return forbidden(String.format("No room with id: (%d)", roomId));
}
Collection<TimeSlot> slots = new ArrayList<>();
if (!room.getOutOfService() && !room.getState().equals(ExamRoom.State.INACTIVE.toString()) &&
isRoomAccessibilitySatisfied(room, aids) && exam.getDuration() != null) {
LocalDate searchDate;
try {
searchDate = parseSearchDate(day, exam, room);
} catch (NotFoundException e) {
return notFound();
}
// users reservations starting from now
List<Reservation> reservations = Ebean.find(Reservation.class)
.fetch("enrolment.exam")
.where()
.eq("user", user)
.gt("startAt", searchDate.toDate())
.findList();
// Resolve eligible machines based on software and accessibility requirements
List<ExamMachine> machines = getEligibleMachines(room, aids, exam);
LocalDate endOfSearch = getEndSearchDate(exam, searchDate);
while (!searchDate.isAfter(endOfSearch)) {
Set<TimeSlot> timeSlots = getExamSlots(user, room, exam, searchDate, reservations, machines);
if (!timeSlots.isEmpty()) {
slots.addAll(timeSlots);
}
searchDate = searchDate.plusDays(1);
}
}
return ok(Json.toJson(slots));
}
示例12: read
import org.joda.time.LocalDate; //導入依賴的package包/類
@Override
public LocalDate read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
return formatter.parseLocalDate(date);
}
}
示例13: createInvoice
import org.joda.time.LocalDate; //導入依賴的package包/類
public static Invoice createInvoice(DateTime createdDate, LocalDate invoiceDate,
List<InvoiceItem> invoiceItems) {
UUID id = UUID.randomUUID();
Invoice invoice = Mockito.mock(Invoice.class,
Mockito.withSettings().defaultAnswer(RETURNS_SMART_NULLS.get()));
when(invoice.getId()).thenReturn(id);
when(invoice.getCreatedDate()).thenReturn(createdDate);
when(invoice.getInvoiceDate()).thenReturn(invoiceDate);
when(invoice.getInvoiceItems()).thenReturn(invoiceItems);
return invoice;
}
示例14: testSqlDateConversion
import org.joda.time.LocalDate; //導入依賴的package包/類
/**
* Tests SQL date conversion to string via databaseSafeStringtoRecordValue
*
* @throws SQLException If a SQL exception is thrown.
*/
@Test
public void testSqlDateConversion() throws SQLException {
ResultSet rs = mock(ResultSet.class);
LocalDate localDate1 = new LocalDate(2010, 1, 1);
LocalDate localDate2 = new LocalDate(2010, 12, 21);
LocalDate localDate3 = new LocalDate(100, 1, 1);
LocalDate localDate4 = new LocalDate(9999, 12, 31);
java.sql.Date date1 = new java.sql.Date(localDate1.toDate().getTime());
java.sql.Date date2 = new java.sql.Date(localDate2.toDate().getTime());
java.sql.Date date3 = new java.sql.Date(localDate3.toDate().getTime());
java.sql.Date date4 = new java.sql.Date(localDate4.toDate().getTime());
when(rs.getDate(1)).thenReturn(date1);
when(rs.getDate(2)).thenReturn(date2);
when(rs.getDate(3)).thenReturn(date3);
when(rs.getDate(4)).thenReturn(date4);
Record record = testDialect.resultSetToRecord(rs, ImmutableList.of(
column("Date1", DataType.DATE),
column("Date2", DataType.DATE),
column("Date3", DataType.DATE),
column("Date4", DataType.DATE)
));
assertEquals(localDate1, record.getLocalDate("Date1"));
assertEquals(localDate2, record.getLocalDate("Date2"));
assertEquals(localDate3, record.getLocalDate("Date3"));
assertEquals(localDate4, record.getLocalDate("Date4"));
assertEquals(date1, record.getDate("Date1"));
assertEquals(date2, record.getDate("Date2"));
assertEquals(date3, record.getDate("Date3"));
assertEquals(date4, record.getDate("Date4"));
}
示例15: putDate
import org.joda.time.LocalDate; //導入依賴的package包/類
@Test
public void putDate() throws Exception {
DateWrapper body = new DateWrapper();
body.withField(new LocalDate(1, 1, 1));
body.withLeap(new LocalDate(2016, 2, 29));
client.primitives().putDate(body);
}