本文整理汇总了Java中org.threeten.bp.LocalDate类的典型用法代码示例。如果您正苦于以下问题:Java LocalDate类的具体用法?Java LocalDate怎么用?Java LocalDate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalDate类属于org.threeten.bp包,在下文中一共展示了LocalDate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLastWeeksMessages
import org.threeten.bp.LocalDate; //导入依赖的package包/类
private List<SlackMessagePosted> getLastWeeksMessages() {
SlackSession slackSession = getSlackSession();
SlackChannel slackChannel = slackSession.findChannelByName("publicaties");
ChannelHistoryModule channelHistoryModule = ChannelHistoryModuleFactory.createChannelHistoryModule(slackSession);
List<SlackMessagePosted> lastWeeksMesages = IntStream.of(7, 6, 5, 4, 3, 2, 1)
.mapToObj(daysAgo -> LocalDate.now().minus(daysAgo, ChronoUnit.DAYS))
.flatMap(date -> getMessagesOfDay(slackChannel, channelHistoryModule, date))
.collect(toList());
try {
slackSession.disconnect();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return lastWeeksMesages;
}
示例2: fetchHistoryOfChannel
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
Map<String, String> params = new HashMap<>();
params.put("channel", channelId);
if (day != null) {
ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
params.put("oldest", convertDateToSlackTimestamp(start));
params.put("latest", convertDateToSlackTimestamp(end));
}
if (numberOfMessages > -1) {
params.put("count", String.valueOf(numberOfMessages));
} else {
params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE));
}
SlackChannel channel =session.findChannelById(channelId);
switch (channel.getType()) {
case INSTANT_MESSAGING:
return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND);
case PRIVATE_GROUP:
return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND);
default:
return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND);
}
}
示例3: parameterToString
import org.threeten.bp.LocalDate; //导入依赖的package包/类
/**
* Format the given parameter object into string.
*
* @param param Parameter
* @return String representation of the parameter
*/
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
String jsonStr = json.serialize(param);
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection)param) {
if (b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
}
示例4: onCreate
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidThreeTen.init(this);
start_date = LocalDate.now();
end_date = LocalDate.now();
seed = DEFAULT_SEED;
setContentView(R.layout.activity_main);
// Load an ad into the AdMob banner view.
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
potd_list_view = (ListView) findViewById(R.id.potd_list);
generate_potd_list();
}
示例5: getView
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
// Get the data item for this position
Map.Entry<LocalDate, String> potd = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.potd_list_item, parent, false);
}
// Lookup view for data population
TextView date = (TextView) convertView.findViewById(R.id.potd_date);
TextView password = (TextView) convertView.findViewById(R.id.password);
// Populate the data into the template view using the data object
if (potd != null) {
date.setText(potd.getKey().toString());
password.setText(potd.getValue());
}
// Return the completed view to render on screen
return convertView;
}
示例6: generate_multi
import org.threeten.bp.LocalDate; //导入依赖的package包/类
static Map<LocalDate, String> generate_multi(LocalDate start_date, LocalDate end_date, String seed) {
if (start_date.isAfter(end_date)) {
throw new IllegalArgumentException();
}
int days = (int) (1 + ChronoUnit.DAYS.between(start_date, end_date));
// Now let's generate one password for each day
Map<LocalDate, String> password_list = new HashMap<>();
LocalDate date = start_date;
for (int i = 0; i < days; i++) {
password_list.put(date, generate(date, seed));
date = date.plusDays(1);
}
return password_list;
}
示例7: fetchHistoryOfChannel
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
Map<String, String> params = new HashMap<>();
params.put("channel", channelId);
if (day != null) {
ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
params.put("oldest", convertDateToSlackTimestamp(start));
params.put("latest", convertDateToSlackTimestamp(end));
}
if (numberOfMessages > -1) {
params.put("count", String.valueOf(numberOfMessages));
} else {
params.put("count", String.valueOf(1000));
}
return fetchHistoryOfChannel(params);
}
示例8: should_restore_from_parcelable
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Test
public void should_restore_from_parcelable() {
// Given
LocalDate day = LocalDate.of(1985, 5, 15);
List<ScheduleSlot> slots = singletonList(new ScheduleSlot(null, null));
ScheduleDay scheduleDay = new ScheduleDay(day, slots);
// When
Parcel parcel = Parcel.obtain();
scheduleDay.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
ScheduleDay fromParcel = ScheduleDay.CREATOR.createFromParcel(parcel);
// Then
assertThat(fromParcel.getDay()).isEqualTo(day);
assertThat(fromParcel.getSlots()).hasSize(1);
}
示例9: fetchData
import org.threeten.bp.LocalDate; //导入依赖的package包/类
private void fetchData(Action0 termination) {
this.tracker = this.wakatimeClient.fetchLastSevenDays(HeaderFormatter.get(realm))
.observeOn(uiScheduler)
.subscribeOn(ioScheduler)
.map(Wrapper::getData)
.doOnError(viewModel::notifyError)
.doOnTerminate(termination)
.subscribe(
data -> {
viewModel.setData(data);
viewModel.setRotationCache(data);
}, throwable -> Timber.e(throwable, "Error while fetching data")
);
this.durationTracker = this.wakatimeClient.fetchDurations(HeaderFormatter.get(realm),
LocalDate.now().format(DateTimeFormatter.ISO_DATE))
.observeOn(uiScheduler)
.subscribeOn(ioScheduler)
.map(DurationWrapper::getData)
.map(this::sumDurations)
.map(this::formatTime)
.doOnError(err -> Timber.w(err, "Error during processing durations"))
.onErrorReturn(error -> "Not available")
.subscribe(time -> viewModel.setTodayTime(time), error ->
Timber.w(error, "Error parsing time"));
}
示例10: call
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
@UiThread
public void call(final Subscriber<? super List<LocalDate>> subscriber) {
checkUiThread();
calendarView.setOnRangeSelectedListener(new OnRangeSelectedListener() {
@Override
public void onRangeSelected(@NonNull MaterialCalendarView widget, @NonNull List<CalendarDay> dates) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(DateHelper.calendarDaysToLocalDates(dates));
}
}
});
subscriber.add(new MainThreadSubscription() {
@Override
protected void onUnsubscribe() {
calendarView.setOnRangeSelectedListener(null);
}
});
}
示例11: call
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
@UiThread
public void call(final Subscriber<? super LocalDate> subscriber) {
checkUiThread();
calendarView.setOnDateChangedListener(new OnDateSelectedListener() {
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(DateHelper.calendarDayToLocalDate(date));
}
}
});
subscriber.add(new MainThreadSubscription() {
@Override
protected void onUnsubscribe() {
calendarView.setOnDateChangedListener(null);
}
});
}
示例12: setUp
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Before
public void setUp() {
gson = new GsonBuilder()
.registerTypeHierarchyAdapter(Object.class, new RequiredFieldDeserializer())
.registerTypeAdapter(LocalDate.class, new MillisecondsLocalDateAdapter())
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
return fieldAttributes.getAnnotation(GsonExclude.class) != null;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
}
示例13: testOtherTypeAdaptersAreStillWorking
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Test
public void testOtherTypeAdaptersAreStillWorking() {
TestInnerClass innerClass = TestInnerClass.builder()
.requiredObject("obj")
.build();
TestClass testClass = TestClass.builder()
.innerRequiredObject(innerClass)
.requiredField("obj")
.excluded("Something")
.date(LocalDate.now())
.build();
String value = gson.toJson(testClass);
MillisecondsLocalDateAdapter adapter = new MillisecondsLocalDateAdapter();
String serializedDate = adapter.serialize(testClass.date, LocalDate.class, null).getAsString();
assertThat(value.contains(serializedDate), is(true));
}
示例14: fetchUpdatingHistoryOfChannel
import org.threeten.bp.LocalDate; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchUpdatingHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
List<SlackMessagePosted> messages = fetchHistoryOfChannel(channelId, day, numberOfMessages);
session.addReactionAddedListener(new ChannelHistoryReactionAddedListener(messages));
session.addReactionRemovedListener(new ChannelHistoryReactionRemovedListener(messages));
session.addMessagePostedListener(new ChannelHistoryMessagePostedListener(messages));
return messages;
}
示例15: JSON
import org.threeten.bp.LocalDate; //导入依赖的package包/类
public JSON() {
gson = new GsonBuilder()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
.create();
}