本文整理汇总了Java中org.joda.time.LocalTime类的典型用法代码示例。如果您正苦于以下问题:Java LocalTime类的具体用法?Java LocalTime怎么用?Java LocalTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalTime类属于org.joda.time包,在下文中一共展示了LocalTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TIME
import org.joda.time.LocalTime; //导入依赖的package包/类
public static String TIME(Integer hours, Integer minutes, Integer seconds, String timePattern){
if(hours==null || minutes==null || seconds==null) {
if(log.isDebugEnabled()){
log.debug("None of the arguments can be null.");
}
return null;
}
LocalTime lt=new LocalTime(hours,minutes,seconds);
if(timePattern==null) {
return lt.toString(DateTimeFormat.longTime());
}
else{
try{
// Try to convert to a pattern
DateTimeFormatter dtf = DateTimeFormat.forPattern(timePattern);
return lt.toString(dtf);
}
catch (IllegalArgumentException ex){
// Fallback to the default solution
return lt.toString(DateTimeFormat.longTime());
}
}
}
示例2: getDeadline
import org.joda.time.LocalTime; //导入依赖的package包/类
private DateTime getDeadline(LocalDate date) {
Settings settings = settingsRepo.findById(1);
int deadlineDays = settings.getDeadlineDays();
LocalTime deadlineTime = settings.getDeadline();
date = date.minusDays(deadlineDays);
while (this.holidaysRepo.findByIdHoliday(date) != null) {
date = date.minusDays(1);
}
// Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
//return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);
// When we ll change deadline time to utc, use this:
//return date.toLocalDateTime(deadlineTime).toDateTime(DateTimeZone.UTC);
return date.toLocalDateTime(deadlineTime).toDateTime(); // To default zone
}
示例3: testDailyMenusIdPut_400_DailyMenuEntity_BadRequest
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void testDailyMenusIdPut_400_DailyMenuEntity_BadRequest() throws Exception
{
mockFoodList.add(mockFood2);
mockDailyMenu.setFoods(mockFoodList);
mockDailyMenuList.add(mockDailyMenu);
LocalTime deadline = new LocalTime(0, 0);
Settings sets = new Settings(1, deadline, null, "€", "notes", "tos", "policy", 0, 0, "", "");
given(mockSettingsRepository.findOne(1)).willReturn(sets);
given(mockDailyMenuRepository.findById(6)).willReturn(mockDailyMenu);
//given(mockHolidaysRepository.findByIdHoliday(new LocalDate(2017,04,28))).willReturn(null);
mockMvc.perform(put("/api/dailyMenus/{id}", "6")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content("{}")
).andExpect(status().isBadRequest())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
示例4: right
import org.joda.time.LocalTime; //导入依赖的package包/类
/**
* 定义微信菜单
*/
@WxButton(group = WxButton.Group.RIGHT, main = true, name = "Hi")
public String right(WxUser wxUser) {
log.info("wxUser:{}", wxUser);
int hourOfDay = LocalTime.now().getHourOfDay();
String wenhou;
if (hourOfDay >= 7 && hourOfDay < 12) {
wenhou = "上午好";
} else if (hourOfDay == 12) {
wenhou = "中午好";
} else if (hourOfDay > 12 && hourOfDay < 19) {
wenhou = "下午好";
} else if (hourOfDay >= 19 && hourOfDay < 22) {
wenhou = "晚上好";
} else {
wenhou = "太晚了。生活再忙,也要休息";
}
log.info("wenhou:{}", wenhou);
return wxUser.getNickName() + "," + wenhou;
}
示例5: setUpTime
import org.joda.time.LocalTime; //导入依赖的package包/类
private void setUpTime() {
mDisposableTaskDate.setText(DATE_FORMATTER.print(LocalDate.now()));
mDisposableTaskTime.setText(TIME_FORMATTER.print(LocalTime.now()));
if (mTimedTask == null) {
mDailyTaskRadio.setChecked(true);
return;
}
if (mTimedTask.isDisposable()) {
mDisposableTaskRadio.setChecked(true);
mDisposableTaskTime.setText(TIME_FORMATTER.print(mTimedTask.getMillis()));
mDisposableTaskDate.setText(DATE_FORMATTER.print(mTimedTask.getMillis()));
return;
}
LocalTime time = LocalTime.fromMillisOfDay(mTimedTask.getMillis());
mDailyTaskTimePicker.setCurrentHour(time.getHourOfDay());
mDailyTaskTimePicker.setCurrentMinute(time.getMinuteOfHour());
if (mTimedTask.isDaily()) {
mDailyTaskRadio.setChecked(true);
} else {
mWeeklyTaskRadio.setChecked(true);
for (int i = 0; i < mDayOfWeekCheckBoxes.size(); i++) {
mDayOfWeekCheckBoxes.get(i).setChecked(mTimedTask.hasDayOfWeek(i + 1));
}
}
}
示例6: createDisposableTask
import org.joda.time.LocalTime; //导入依赖的package包/类
private TimedTask createDisposableTask() {
LocalTime time = TIME_FORMATTER.parseLocalTime(mDisposableTaskTime.getText().toString());
LocalDate date = DATE_FORMATTER.parseLocalDate(mDisposableTaskDate.getText().toString());
LocalDateTime dateTime = new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
time.getHourOfDay(), time.getMinuteOfHour());
if (dateTime.isBefore(LocalDateTime.now())) {
Toast.makeText(this, R.string.text_disposable_task_time_before_now, Toast.LENGTH_SHORT).show();
return null;
}
return TimedTask.disposableTask(dateTime, mScriptFile.getPath(), ExecutionConfig.getDefault());
}
示例7: bind
import org.joda.time.LocalTime; //导入依赖的package包/类
private void bind(Station station) {
StationFacilities facilities = station.getStationFacilities();
StringBuilder openingHoursString = new StringBuilder();
for (int i = 0; i < 7; i++) {
LocalTime[] openingHours = facilities.getOpeningHours(i);
if (openingHours == null) {
openingHoursString.append("Closed");
} else {
openingHoursString.append(openingHours[0].toString("HH:mm")).append(" - ").append(openingHours[1].toString("HH:mm")).append("\n");
}
}
((TextView) findViewById(R.id.text_hours)).setText(openingHoursString.toString());
((TextView) findViewById(R.id.text_station)).setText(station.getLocalizedName());
((TextView) findViewById(R.id.text_address)).setText(String.format("%s %s %s", facilities.getStreet(), facilities.getZip(), facilities.getCity()));
findViewById(R.id.image_tram).setVisibility(facilities.hasTram() ? View.VISIBLE : View.GONE);
findViewById(R.id.image_bus).setVisibility(facilities.hasBus() ? View.VISIBLE : View.GONE);
findViewById(R.id.image_subway).setVisibility(facilities.hasMetro() ? View.VISIBLE : View.GONE);
// TODO: display information on accessibility
}
示例8: convert
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void convert() throws Exception {
String dateString = "06/27/2017 12:30";
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Date date = df.parse(dateString);
LocalTime localTime = (LocalTime) converter.convert(date, TypeToken.of(LocalTime.class));
assertEquals(12, localTime.getHourOfDay());
assertEquals(30, localTime.getMinuteOfHour());
LocalDate localDate = (LocalDate) converter.convert(date, TypeToken.of(LocalDate.class));
assertEquals(2017, localDate.getYear());
assertEquals(6, localDate.getMonthOfYear());
assertEquals(27, localDate.getDayOfMonth());
LocalDateTime localDateTime = (LocalDateTime) converter.convert(date, TypeToken.of(LocalDateTime.class));
assertEquals(12, localDateTime.getHourOfDay());
assertEquals(30, localDateTime.getMinuteOfHour());
assertEquals(2017, localDateTime.getYear());
assertEquals(6, localDateTime.getMonthOfYear());
assertEquals(27, localDateTime.getDayOfMonth());
}
示例9: convert
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void convert() throws Exception {
String dateString = "1985-09-03 13:30";
LocalTime localTime = (LocalTime) converter.convert(dateString, TypeToken.of(LocalTime.class));
assertEquals(13, localTime.getHourOfDay());
assertEquals(30, localTime.getMinuteOfHour());
LocalDate localDate = (LocalDate) converter.convert(dateString, TypeToken.of(LocalDate.class));
assertEquals(1985, localDate.getYear());
assertEquals(9, localDate.getMonthOfYear());
assertEquals(3, localDate.getDayOfMonth());
LocalDateTime localDateTime = (LocalDateTime) converter.convert(dateString, TypeToken.of(LocalDateTime.class));
assertEquals(13, localDateTime.getHourOfDay());
assertEquals(30, localDateTime.getMinuteOfHour());
assertEquals(1985, localDateTime.getYear());
assertEquals(9, localDateTime.getMonthOfYear());
assertEquals(3, localDateTime.getDayOfMonth());
}
示例10: testBasicMatch
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void testBasicMatch()
{
TemplatedUtterance utterance = new TemplatedUtterance(tokenizer.tokenize("at {time}"));
String[] input = tokenizer.tokenize("at 6:45am");
Slots slots = new Slots();
Context context = new Context();
TimeSlot slot = new TimeSlot("time");
slots.add(slot);
TemplatedUtteranceMatch match = utterance.matches(input, slots, context);
assertThat(match, is(notNullValue()));
assertThat(match.isMatched(), is(true));
assertThat(match.getSlotMatches().size(), is(1));
SlotMatch slotMatch = match.getSlotMatches().get(slot);
assertThat(slotMatch, is(notNullValue()));
assertThat(slotMatch.getOrginalValue(), is("6:45am"));
assertThat(slotMatch.getValue(), is(new LocalTime(6, 45)));
}
示例11: sumDeHours
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void sumDeHours()
{
// Fixture Setup
final LocalTime Hour1 = new LocalTime( 1, 12, 25 );
final LocalTime Hour2 = new LocalTime( 2, 12, 25 );
final LocalTime HourEsperada = new LocalTime( 3, 12, 25 );
// Exercise SUT
final int novaHour = Hour1.getHourOfDay() + Hour2.getHourOfDay();
// Result Verification
Assert.assertEquals( novaHour, HourEsperada.getHourOfDay() );
// Fixture Teardown
}
示例12: getHuntingDayInterval
import org.joda.time.LocalTime; //导入依赖的package包/类
/**
* Converts given date and duration into a legal hunting day interval. Duration is rounded down
* to half an hour resolution and, if needed, replaced with a legal default value in case a
* value out of acceptable range is provided.
*/
@Nonnull
public static Interval getHuntingDayInterval(
@Nonnull final LocalDate date, @Nullable final Float huntingDurationInHours) {
Objects.requireNonNull(date, "date is null");
final Float legalizedDuration = Optional.ofNullable(huntingDurationInHours)
.filter(MooseDataCardHuntingDayField.HUNTING_DAY_DURATION::isValueInRange)
.orElseGet(() -> Integer.valueOf(DEFAULT_DURATION).floatValue());
final double durationRoundedDownToNearestHalfHour = roundDownToNearestHalfHour(legalizedDuration.doubleValue());
final double durationRoundedToNearestHour = Math.ceil(durationRoundedDownToNearestHalfHour);
final DateTime startTime = defaultStartTimeMustBeAdvanced(durationRoundedDownToNearestHalfHour)
? date.toDateTime(new LocalTime(
(int) (48.0 - durationRoundedToNearestHour),
(int) ((durationRoundedToNearestHour - durationRoundedDownToNearestHalfHour) * 60.0)))
: date.toDateTime(DEFAULT_HUNTING_DAY_START_TIME);
return new Interval(
startTime.withZone(Constants.DEFAULT_TIMEZONE),
startTime.plusMinutes((int) (durationRoundedDownToNearestHalfHour * 60.0))
.withZone(Constants.DEFAULT_TIMEZONE));
}
示例13: parsesJourneyDetails
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test
public void parsesJourneyDetails() throws IOException {
try (InputStream is = getClass().getResourceAsStream("journeyDetails.json")) {
JourneyDetailResponse response = sut.readValue(is, JourneyDetailResponse.class);
Assert.assertEquals(6, response.getJourneyDetail().getStops().getStop().size());
Assert.assertEquals(1, response.getJourneyDetail().getNames().getName().size());
Assert.assertEquals(1, response.getJourneyDetail().getTypes().getType().size());
Assert.assertEquals(1, response.getJourneyDetail().getOperators().getOperator().size());
Assert.assertEquals(1, response.getJourneyDetail().getNotes().getNote().size());
final Stop stop = response.getJourneyDetail().getStops().getStop().get(0);
Assert.assertEquals("Frankfurt(Main)Hbf", stop.getName());
Assert.assertEquals("8000105", stop.getId());
Assert.assertEquals(8.663785, stop.getLon(), 0.000001);
Assert.assertEquals(50.107149, stop.getLat(), 0.000001);
Assert.assertEquals(LocalTime.parse("15:02"), stop.getDepTime());
Assert.assertEquals(LocalDate.parse("2016-02-22"), stop.getDepDate());
Assert.assertEquals(0, stop.getRouteIdx().intValue());
Assert.assertEquals("13", stop.getTrack());
}
}
示例14: createHuntingDayDTO
import org.joda.time.LocalTime; //导入依赖的package包/类
private static GroupHuntingDayDTO createHuntingDayDTO(final HuntingClubGroup group, final boolean withHounds) {
final GroupHuntingDayDTO dto = new GroupHuntingDayDTO();
dto.setHuntingGroupId(group.getId());
dto.setStartDate(today());
dto.setEndDate(today());
dto.setStartTime(LocalTime.now());
dto.setEndTime(LocalTime.now().plusHours(1));
dto.setBreakDurationInMinutes(10);
dto.setNumberOfHunters(1);
dto.setHuntingMethod(getAnyHuntingMethodByHounds(withHounds));
return dto;
}
示例15: testUpdateHarvest_whenSpeciesIsNotValid
import org.joda.time.LocalTime; //导入依赖的package包/类
@Test(expected = HarvestPermitSpeciesAmountNotFound.class)
public void testUpdateHarvest_whenSpeciesIsNotValid() {
withPerson(author -> {
final GameSpecies species = model().newGameSpecies(true);
final Harvest harvest = model().newHarvest(species, author);
final HarvestPermit permit = model().newHarvestPermit(true);
final HarvestPermitSpeciesAmount amount = model().newHarvestPermitSpeciesAmount(permit, species);
model().newHarvestReportFields(species, true);
onSavedAndAuthenticated(createUser(author), () -> {
invokeUpdateHarvest(create(harvest, 5)
.mutate()
.withPermitNumber(permit.getPermitNumber())
.withPointOfTime(amount.getBeginDate().minusDays(1).toLocalDateTime(LocalTime.MIDNIGHT))
.build());
});
});
}