Java Code Examples for org.threeten.bp.LocalDate#getYear()
The following examples show how to use
org.threeten.bp.LocalDate#getYear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicTimelineAdapterWithThirdLib.java From JReadHub with GNU General Public License v3.0 | 6 votes |
@Override protected void convert(BaseViewHolder holder, RelevantTopicBean relevantTopicBean) { LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate(); int year = date.getYear(); int month = date.getMonthValue(); int day = date.getDayOfMonth(); if (year == OffsetDateTime.now().getYear()) { holder.setText(R.id.txt_date, mContext.getString(R.string.month__day, month, day)); } else { SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year)); spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)), spannableTitle.toString().indexOf("\n") + 1, spannableTitle.toString().indexOf("\n") + 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); holder.setText(R.id.txt_date, spannableTitle); } holder.setText(R.id.txt_topic_trace_content, relevantTopicBean.getTitle()); holder.setVisible(R.id.view_top_line, holder.getItemViewType() == VIEW_TYPE_TOP || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true); holder.setVisible(R.id.view_bottom_line, holder.getItemViewType() == VIEW_TYPE_BOTTOM || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true); }
Example 2
Source File: TopicTimelineAdapter.java From JReadHub with GNU General Public License v3.0 | 6 votes |
@Override public void bindData(RelevantTopicBean relevantTopicBean, int position) { mRelevantTopicBean = relevantTopicBean; LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate(); int year = date.getYear(); int month = date.getMonthValue(); int day = date.getDayOfMonth(); if (year == OffsetDateTime.now().getYear()) { mTxtDate.setText(mContext.getString(R.string.month__day, month, day)); } else { SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year)); spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)), spannableTitle.toString().indexOf("\n") + 1, spannableTitle.toString().indexOf("\n") + 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mTxtDate.setText(spannableTitle); } mTxtContent.setText(relevantTopicBean.getTitle()); mDividerTop.setVisibility(getItemViewType() == VIEW_TYPE_TOP || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE); mDividerBottom.setVisibility(getItemViewType() == VIEW_TYPE_BOTTOM || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE); }
Example 3
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era and day-of-year fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year, otherwise an exception will be thrown. * The Japanese day-of-year is reset when the era changes. * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param dayOfYear the Japanese day-of-year, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-year is invalid for the year */ static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { Jdk8Methods.requireNonNull(era, "era"); if (yearOfEra < 1) { throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); } LocalDate eraStartDate = era.startDate(); LocalDate eraEndDate = era.endDate(); if (yearOfEra == 1) { dayOfYear += eraStartDate.getDayOfYear() - 1; if (dayOfYear > eraStartDate.lengthOfYear()) { throw new DateTimeException("DayOfYear exceeds maximum allowed in the first year of era " + era); } } int yearOffset = eraStartDate.getYear() - 1; LocalDate isoDate = LocalDate.ofYearDay(yearOfEra + yearOffset, dayOfYear); if (isoDate.isBefore(eraStartDate) || isoDate.isAfter(eraEndDate)) { throw new DateTimeException("Requested date is outside bounds of era " + era); } return new JapaneseDate(era, yearOfEra, isoDate); }
Example 4
Source File: TestTemporalAdjusters.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void test_next() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); for (DayOfWeek dow : DayOfWeek.values()) { LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date); assertSame(test.getDayOfWeek(), dow, date + " " + test); if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); assertTrue(dayDiff > 0 && dayDiff < 8); } else { assertSame(month, Month.DECEMBER); assertTrue(date.getDayOfMonth() > 24); assertEquals(test.getYear(), 2008); assertSame(test.getMonth(), Month.JANUARY); assertTrue(test.getDayOfMonth() < 8); } } } } }
Example 5
Source File: TestTemporalAdjusters.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void test_previous() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); for (DayOfWeek dow : DayOfWeek.values()) { LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date); assertSame(test.getDayOfWeek(), dow, date + " " + test); if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test); } else { assertSame(month, Month.JANUARY); assertTrue(date.getDayOfMonth() < 8); assertEquals(test.getYear(), 2006); assertSame(test.getMonth(), Month.DECEMBER); assertTrue(test.getDayOfMonth() > 24); } } } } }
Example 6
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates an instance from an ISO date. * * @param isoDate the standard local date, validated not null */ JapaneseDate(LocalDate isoDate) { if (isoDate.isBefore(MIN_DATE)) { throw new DateTimeException("Minimum supported date is January 1st Meiji 6"); } this.era = JapaneseEra.from(isoDate); int yearOffset = this.era.startDate().getYear() - 1; this.yearOfEra = isoDate.getYear() - yearOffset; this.isoDate = isoDate; }
Example 7
Source File: TestTemporalAdjusters.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test_nextOrSame() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); for (DayOfWeek dow : DayOfWeek.values()) { LocalDate test = (LocalDate) TemporalAdjusters.nextOrSame(dow).adjustInto(date); assertSame(test.getDayOfWeek(), dow); if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); assertTrue(dayDiff < 8); assertEquals(date.equals(test), date.getDayOfWeek() == dow); } else { assertFalse(date.getDayOfWeek() == dow); assertSame(month, Month.DECEMBER); assertTrue(date.getDayOfMonth() > 24); assertEquals(test.getYear(), 2008); assertSame(test.getMonth(), Month.JANUARY); assertTrue(test.getDayOfMonth() < 8); } } } } }
Example 8
Source File: TestTemporalAdjusters.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test_previousOrSame() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); for (DayOfWeek dow : DayOfWeek.values()) { LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date); assertSame(test.getDayOfWeek(), dow); if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); assertTrue(dayDiff <= 0 && dayDiff > -7); assertEquals(date.equals(test), date.getDayOfWeek() == dow); } else { assertFalse(date.getDayOfWeek() == dow); assertSame(month, Month.JANUARY); assertTrue(date.getDayOfMonth() < 7); assertEquals(test.getYear(), 2006); assertSame(test.getMonth(), Month.DECEMBER); assertTrue(test.getDayOfMonth() > 25); } } } } }
Example 9
Source File: TestIsoFields.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_loop() { // loop round at least one 400 year cycle, including before 1970 LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960 int year = 1960; int wby = 1960; int weekLen = 52; int week = 1; while (date.getYear() < 2400) { DayOfWeek loopDow = date.getDayOfWeek(); if (date.getYear() != year) { year = date.getYear(); } if (loopDow == MONDAY) { week++; if ((week == 53 && weekLen == 52) || week == 54) { week = 1; LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1); DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek(); weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52); wby++; } } assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek()); date = date.plusDays(1); } }
Example 10
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Jdk8Methods.requireNonNull(era, "era"); if (yearOfEra < 1) { throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); } LocalDate eraStartDate = era.startDate(); LocalDate eraEndDate = era.endDate(); int yearOffset = eraStartDate.getYear() - 1; LocalDate date = LocalDate.of(yearOfEra + yearOffset, month, dayOfMonth); if (date.isBefore(eraStartDate) || date.isAfter(eraEndDate)) { throw new DateTimeException("Requested date is outside bounds of era " + era); } return new JapaneseDate(era, yearOfEra, date); }