cesiumlanguagewriter.YearMonthDay类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中cesiumlanguagewriter.YearMonthDay类的一些代码示例,展示了YearMonthDay类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonthDay类的具体详情如下:
包路径:cesiumlanguagewriter.YearMonthDay
类名称:YearMonthDay

YearMonthDay介绍

[英]Represents a calendar year, month, and day.
[中]表示日历年、月和日。

代码示例

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Initializes a {@link GregorianDate} from the provided values. The
  4. fractional portion of the {@code daysOfYear} will be converted into
  5. hours, minutes, and seconds.
  6. * @param year The year.
  7. * @param daysOfYear The day of year plus the fractional portion of the day
  8. (in the range 1 through the number of days in the given year).
  9. */
  10. public GregorianDate(int year, double daysOfYear) {
  11. m_yearMonthDay = new YearMonthDay(year, (int) daysOfYear);
  12. double fraction = daysOfYear % 1;
  13. double seconds = fraction * TimeConstants.SecondsPerDay;
  14. m_hour = (int) (seconds / SecondsPerHour);
  15. seconds -= m_hour * SecondsPerHour;
  16. m_minute = (int) (seconds / SecondsPerMinute);
  17. seconds -= m_minute * SecondsPerMinute;
  18. m_second = seconds;
  19. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Returns {@code true} if {@code left} is greater than or equal to {@code right}.
  4. * @param left The instance to compare to {@code right}.
  5. * @param right The instance to compare to {@code left}.
  6. * @return
  7. {@code true} if {@code left} is greater than or equal to {@code right}; otherwise, {@code false}.
  8. */
  9. @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean >=(YearMonthDay,YearMonthDay)'")
  10. public static boolean greaterThanOrEqual(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right) {
  11. return left.compareTo(right) >= 0;
  12. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Indicates whether the year, month, and day are a valid representation.
  4. * @param year The year.
  5. * @param month The month of the year (in the range 1 through 12)
  6. * @param day The day of the month (in the range 1 through the number of days in
  7. {@code month})
  8. * @return {@code true} if the representation is valid and
  9. {@code false} if it is not.
  10. */
  11. public static boolean isValidDate(int year, int month, int day) {
  12. return year >= 1 && year <= 9999 && month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(year, month);
  13. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. * Gets the Julian day number for this {@link YearMonthDay} instance,
  3. assuming noon on this day.
  4. */
  5. public final int getJulianDayNumber() {
  6. // Algorithm from page 604 of the Explanatory Supplement to the
  7. // Astronomical Almanac (Seidelmann 1992).
  8. int a = (getMonth() - 14) / 12;
  9. int b = getYear() + 4800 + a;
  10. return 1461 * b / 4 + 367 * (getMonth() - 2 - 12 * a) / 12 - 3 * ((b + 100) / 100) / 4 + getDay() - 32075;
  11. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. * Gets the day of the year (in the range 1 through the number of days in the year).
  3. */
  4. public final int getDayOfYear() {
  5. int[] cumulativeMonthTable = getCumulativeMonthTable(getYear());
  6. return getDay() + cumulativeMonthTable[m_month];
  7. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. @Test
  2. public final void testDefaultConstructedIsValid() {
  3. YearMonthDay ymd = new YearMonthDay();
  4. YearMonthDay ymd2 = new YearMonthDay(ymd.getYear(), ymd.getMonth(), ymd.getDay());
  5. AssertHelper.assertEquals(ymd, ymd2);
  6. AssertHelper.assertEquals(ymd.getDayOfWeek(), ymd2.getDayOfWeek());
  7. Assert.assertEquals((int) ymd.getDayOfYear(), (int) ymd2.getDayOfYear());
  8. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. 2001
  2. };
  3. Assert.assertTrue(YearMonthDay.isLeapYear(years[0]));
  4. Assert.assertFalse(YearMonthDay.isLeapYear(years[1]));
  5. for (final int year : years) {
  6. int cumulativeDays = 0;
  7. for (int month = 1; month <= 12; ++month) {
  8. YearMonthDay ymd = new YearMonthDay(year, cumulativeDays + 1);
  9. Assert.assertEquals((int) year, (int) ymd.getYear());
  10. Assert.assertEquals((int) month, (int) ymd.getMonth());
  11. Assert.assertEquals((int) 1, (int) ymd.getDay());
  12. int daysInMonth = YearMonthDay.daysInMonth(year, month);
  13. ymd = new YearMonthDay(year, cumulativeDays + daysInMonth);
  14. Assert.assertEquals((int) year, (int) ymd.getYear());
  15. Assert.assertEquals((int) month, (int) ymd.getMonth());
  16. Assert.assertEquals((int) daysInMonth, (int) ymd.getDay());
  17. cumulativeDays += daysInMonth;

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Tests that initialization of and access to the structure elements is performed correctly.
  4. */
  5. @Test
  6. public final void testRetainValue() {
  7. YearMonthDay date = new YearMonthDay(2000, 1, 1);
  8. Assert.assertEquals((int) 2000, (int) date.getYear());
  9. Assert.assertEquals((int) 1, (int) date.getMonth());
  10. Assert.assertEquals((int) 1, (int) date.getDay());
  11. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Tests the CompareTo methods and the comparison operators.
  4. */
  5. @Test
  6. public final void testComparisons() {
  7. YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
  8. YearMonthDay ymd2 = new YearMonthDay(2006, 3, 14);
  9. YearMonthDay ymd3 = new YearMonthDay(2006, 5, 26);
  10. Object ymd4 = new YearMonthDay(2004, 2, 21);
  11. Assert.assertTrue(YearMonthDay.equals(ymd1, ymd2));
  12. Assert.assertTrue(YearMonthDay.equals(ymd2, ymd1));
  13. Assert.assertTrue(YearMonthDay.notEquals(ymd1, ymd3));
  14. Assert.assertTrue(YearMonthDay.greaterThanOrEqual(ymd1, ymd2));
  15. Assert.assertTrue(YearMonthDay.lessThanOrEqual(ymd1, ymd2));
  16. Assert.assertTrue(ymd1.compareTo(ymd2) == 0);
  17. Assert.assertTrue(YearMonthDay.lessThan(ymd2, ymd3));
  18. Assert.assertTrue(YearMonthDay.lessThanOrEqual(ymd2, ymd3));
  19. Assert.assertTrue(YearMonthDay.greaterThan(ymd3, ymd2));
  20. Assert.assertTrue(YearMonthDay.greaterThanOrEqual(ymd3, ymd2));
  21. AssertHelper.assertNotEqual(ymd1, ymd4);
  22. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. return false;
  2. if (!YearMonthDay.isValidDate(year, month, day)) {
  3. return false;
  4. boolean dayHasLeapSecond = LeapSeconds.getInstance().doesDayHaveLeapSecond(new YearMonthDay(year, month, day).getJulianDayNumber());
  5. return dayHasLeapSecond && hour == 23 && minute == 59;

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. cesiumlanguagewriter.YearMonthDay yearMonthDay = new YearMonthDay(year, dayOfYear);
  2. if (!isValid(year, yearMonthDay.getMonth(), yearMonthDay.getDay(), hour, minute, second)) {
  3. throw new ArgumentException(CesiumLocalization.getHourMinuteSecondInvalidArgument());

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. YearMonthDay first = new YearMonthDay(2000, 1, 1);
  2. YearMonthDay second = new YearMonthDay(2000, 1, 1);
  3. AssertHelper.assertEquals(first, second);
  4. Assert.assertTrue(first.equalsType(second));
  5. Assert.assertTrue(second.equalsType(first));
  6. Assert.assertEquals((int) 0, (int) first.compareTo(second));
  7. Assert.assertEquals((int) 0, (int) second.compareTo(first));
  8. second = new YearMonthDay(2001, 1, 1);
  9. AssertHelper.assertNotEqual(first, second);
  10. Assert.assertFalse(first.equalsType(second));
  11. Assert.assertFalse(second.equalsType(first));
  12. AssertHelper.assertNotEqual(0, first.compareTo(second));
  13. AssertHelper.assertNotEqual(0, second.compareTo(first));
  14. second = new YearMonthDay(2000, 2, 1);
  15. AssertHelper.assertNotEqual(first, second);
  16. Assert.assertFalse(first.equalsType(second));
  17. Assert.assertFalse(second.equalsType(first));
  18. AssertHelper.assertNotEqual(0, first.compareTo(second));
  19. AssertHelper.assertNotEqual(0, second.compareTo(first));
  20. second = new YearMonthDay(2000, 1, 2);
  21. AssertHelper.assertNotEqual(first, second);
  22. Assert.assertFalse(first.equalsType(second));
  23. Assert.assertFalse(second.equalsType(first));
  24. AssertHelper.assertNotEqual(0, first.compareTo(second));
  25. AssertHelper.assertNotEqual(0, second.compareTo(first));
  26. AssertHelper.assertNotEqual(first, 5);

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Initializes a {@link YearMonthDay} from the provided values.
  4. * @param year The year.
  5. * @param dayOfYear The day of the year
  6. (in the range 1 through the number of days in the year).
  7. */
  8. public YearMonthDay(int year, int dayOfYear) {
  9. if (dayOfYear > daysInYear(year)) {
  10. throw new ArgumentException(CesiumLocalization.getYearMonthDayInvalidArgument(), "dayOfYear");
  11. }
  12. // year is stored zero-indexed
  13. m_year = year - 1;
  14. int[] cumulativeMonthTable = getCumulativeMonthTable(year);
  15. // month is stored zero-indexed
  16. for (m_month = 11; m_month > 0; --m_month) {
  17. if (cumulativeMonthTable[m_month] < dayOfYear) {
  18. break;
  19. }
  20. }
  21. // day is stored zero-indexed
  22. m_day = dayOfYear - cumulativeMonthTable[m_month] - 1;
  23. if (!isValidDate(m_year + 1, m_month + 1, m_day + 1)) {
  24. throw new ArgumentException(CesiumLocalization.getYearMonthDayInvalidArgument());
  25. }
  26. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. @Test
  2. public final void testRoundTripDefaultConstructed() {
  3. YearMonthDay ymd = new YearMonthDay();
  4. YearMonthDay ymd2 = new YearMonthDay(ymd.getJulianDayNumber());
  5. AssertHelper.assertEquals(ymd, ymd2);
  6. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Tests that YearMonthDay.GetHashCode returns something at least reasonably random.
  4. */
  5. @Test
  6. public final void testGetHashCode() {
  7. YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
  8. YearMonthDay ymd2 = new YearMonthDay(2006, 3, 14);
  9. YearMonthDay ymd3 = new YearMonthDay(2006, 5, 26);
  10. Assert.assertEquals((int) ymd1.hashCode(), (int) ymd2.hashCode());
  11. AssertHelper.assertNotEqual(ymd1.hashCode(), ymd3.hashCode());
  12. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. @Test
  2. public final void testDayOfWeek() {
  3. YearMonthDay ymd = new YearMonthDay(2009, 6, 10);
  4. AssertHelper.assertEquals(DayOfWeek.WEDNESDAY, ymd.getDayOfWeek());
  5. ymd = new YearMonthDay(2009, 6, 11);
  6. AssertHelper.assertEquals(DayOfWeek.THURSDAY, ymd.getDayOfWeek());
  7. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Tests the {@code DayOfYear} ({@link YearMonthDay#getDayOfYear get}) property.
  4. */
  5. @Test
  6. public final void testDayOfYear() {
  7. YearMonthDay nonLeapBeforeEndOfFeb = new YearMonthDay(2006, 2, 15);
  8. Assert.assertEquals((int) 46, (int) nonLeapBeforeEndOfFeb.getDayOfYear());
  9. YearMonthDay nonLeapAfterEndOfFeb = new YearMonthDay(2006, 3, 14);
  10. Assert.assertEquals((int) 73, (int) nonLeapAfterEndOfFeb.getDayOfYear());
  11. YearMonthDay leapBeforeEndOfFeb = new YearMonthDay(2008, 2, 15);
  12. Assert.assertEquals((int) 46, (int) leapBeforeEndOfFeb.getDayOfYear());
  13. YearMonthDay leapAfterEndOfFeb = new YearMonthDay(2008, 3, 14);
  14. Assert.assertEquals((int) 74, (int) leapAfterEndOfFeb.getDayOfYear());
  15. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. Assert.assertFalse(YearMonthDay.isValidDate(2000, 0, 1));
  2. Assert.assertTrue(YearMonthDay.isValidDate(2000, 1, 1));
  3. Assert.assertTrue(YearMonthDay.isValidDate(2000, 2, 1));
  4. Assert.assertTrue(YearMonthDay.isValidDate(2000, 3, 1));
  5. Assert.assertTrue(YearMonthDay.isValidDate(2000, 4, 1));
  6. Assert.assertTrue(YearMonthDay.isValidDate(2000, 5, 1));
  7. Assert.assertTrue(YearMonthDay.isValidDate(2000, 6, 1));
  8. Assert.assertTrue(YearMonthDay.isValidDate(2000, 7, 1));
  9. Assert.assertTrue(YearMonthDay.isValidDate(2000, 8, 1));
  10. Assert.assertTrue(YearMonthDay.isValidDate(2000, 9, 1));
  11. Assert.assertTrue(YearMonthDay.isValidDate(2000, 10, 1));
  12. Assert.assertTrue(YearMonthDay.isValidDate(2000, 11, 1));
  13. Assert.assertTrue(YearMonthDay.isValidDate(2000, 12, 1));
  14. Assert.assertFalse(YearMonthDay.isValidDate(2000, 13, 1));
  15. for (int month = 1; month < 13; ++month) {
  16. int daysInMonth = YearMonthDay.daysInMonth(2000, month);
  17. Assert.assertFalse(YearMonthDay.isValidDate(2000, month, 0));
  18. for (int day = 1; day < daysInMonth + 1; ++day) {
  19. Assert.assertTrue(YearMonthDay.isValidDate(2000, month, day));
  20. Assert.assertFalse(YearMonthDay.isValidDate(2000, month, daysInMonth + 1));

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Indicates whether another object is exactly equal to this instance.
  4. * @param obj The object to compare to this instance.
  5. * @return {@code true} if {@code obj} is an instance of this type and represents the same value as this instance; otherwise, {@code false}.
  6. */
  7. @Override
  8. public boolean equals(Object obj) {
  9. return obj instanceof YearMonthDay && equalsType((YearMonthDay) obj);
  10. }

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

  1. /**
  2. *
  3. Tests the {@link YearMonthDay#toString} method.
  4. */
  5. @Test
  6. public final void testToString() {
  7. YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
  8. Assert.assertEquals(ymd1.toString(), "2006:3:14");
  9. }

相关文章