void normalizeYear(CalendarDate date) {
   Date ldate = (Date) date;
   // Set the supposed-to-be-correct Gregorian year first
   // e.g., Showa 90 becomes 2015 (1926 + 90 - 1).
   Era era = ldate.getEra();
   if (era == null || !validateEra(era)) {
     ldate.setNormalizedYear(ldate.getYear());
   } else {
     ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear() - 1);
   }
 }
Ejemplo n.º 2
0
 /** Compares two dates and returns -1, 0, or 1 is the date is before, equal or after */
 public int compareTo(Date other) {
   if (this.getYear() < other.getYear()) return -1;
   else if ((this.getYear() <= other.getYear()) && (this.getIntMonth() < other.getIntMonth()))
     return -1;
   else if ((this.getYear() <= other.getYear())
       && (this.getIntMonth() <= other.getIntMonth())
       && (this.getDay() < other.getDay())) return -1;
   else if ((this.getYear() == other.getYear())
       && (this.getIntMonth() == other.getIntMonth())
       && (this.getDay() == other.getDay())) return 0;
   else return 1;
 }
 public boolean validate(CalendarDate date) {
   Date ldate = (Date) date;
   Era era = ldate.getEra();
   if (era != null) {
     if (!validateEra(era)) {
       return false;
     }
     ldate.setNormalizedYear(era.getSinceDate().getYear() + ldate.getYear());
   } else {
     ldate.setNormalizedYear(ldate.getYear());
   }
   return super.validate(ldate);
 }
 public void test_Date_setYear() {
   Date date = new Date(2005, 12, 30, 12, 15, 45, 1, 2, 0);
   assertTrue(date != null);
   int i = date.setYear(434);
   assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE);
   assertTrue(date.getYear() == 2000);
   i = date.setYear(12121);
   assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE);
   assertTrue(date.getYear() == 2000);
   i = date.setYear(2008);
   assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
   assertTrue(date.getYear() == 2008);
   assertTrue(date.getDateAsString().equals("2008-12-30T12:15:45+02:00"));
   date = null;
 }
Ejemplo n.º 5
0
 /*
    int returnValue <- 0
    String year1 <- getYear()
    String year2 <- anotherDate.getYear()
    if(year1.compareTo(year2) > 0)
       returnValue <- 1
    else if(year1.compareTo(year2) < 0)
       returnValue <- -1
    else if(year1.compareTo(year2) == 0)
       String month1 <- getMonth()
       String month2 <- anotherDate.getMonth()
       if(month1.compareTo(month2) > 0)
          returnValue <- 1
       else if(month1.compareTo(month20 < 0)
          returnValue <- -1
       else if(month1.compareTo(month2) == 0)
          String day1 <- getDay()
          String day2 <- anotherDate.getDay()
          if(day1.compareTo(day2) > 0)
             returnValue <- 1
          else if(day1.compareTo(day2) < 0)
             returnValue <- -1
          else if(day1.compareTo(day2) == 0)
             returnValue <- 0
    return returnValue
 */
 public int compareTo(Date anotherDate) {
   int returnValue = 0;
   String year1 = getYear();
   String year2 = anotherDate.getYear();
   if (year1.compareTo(year2) > 0) {
     returnValue = 1;
   } else if (year1.compareTo(year2) < 0) {
     returnValue = -1;
   } else if (year1.compareTo(year2) == 0) {
     String month1 = getMonth();
     String month2 = anotherDate.getMonth();
     if (month1.compareTo(month2) > 0) {
       returnValue = 1;
     } else if (month1.compareTo(month2) < 0) {
       returnValue = -1;
     } else if (month1.compareTo(month2) == 0) {
       String day1 = getDay();
       String day2 = anotherDate.getDay();
       if (day1.compareTo(day2) > 0) {
         returnValue = 1;
       } else if (day1.compareTo(day2) < 0) {
         returnValue = -1;
       } else if (day1.compareTo(day2) == 0) {
         returnValue = 0;
       }
     }
   }
   return returnValue;
 }
Ejemplo n.º 6
0
 /** 単純な文字列解析。 */
 @Test
 public void parse() {
   Date date = Date.valueOf("12340102", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Ejemplo n.º 7
0
 /** 大きな日付の文字列解析。 */
 @Test
 public void parse_big() {
   Date date = Date.valueOf("29991231", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2999));
   assertThat(date.getMonth(), is(12));
   assertThat(date.getDay(), is(31));
 }
Ejemplo n.º 8
0
 /** 最初の日付の文字列解析。 */
 @Test
 public void parse_zero() {
   Date date = Date.valueOf("00010101", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(1));
 }
Ejemplo n.º 9
0
 /* 136:    */
 /* 137:    */ public final DateTime date_time() /* 138:    */ throws ParseException
       /* 139:    */ {
   /* 140:142 */ switch (this.jj_ntk == -1 ? jj_ntk() : this.jj_ntk)
   /* 141:    */ {
       /* 142:    */ case 4:
       /* 143:    */ case 5:
       /* 144:    */ case 6:
       /* 145:    */ case 7:
       /* 146:    */ case 8:
       /* 147:    */ case 9:
       /* 148:    */ case 10:
       /* 149:150 */ day_of_week();
       /* 150:151 */ jj_consume_token(3);
       /* 151:152 */ break;
       /* 152:    */ default:
       /* 153:154 */ this.jj_la1[1] = this.jj_gen;
       /* 154:    */ }
   /* 155:157 */ Date d = date();
   /* 156:158 */ Time t = time();
   /* 157:159 */ return new DateTime(
       d.getYear(),
       d.getMonth(),
       d.getDay(),
       t.getHour(),
       t.getMinute(),
       t.getSecond(),
       t.getZone());
   /* 158:    */ }
 public void test_Date_setDateAsString() {
   Date date = new Date(2007, 10, 23, 14, 15, 16, 1, 3, 0);
   assertTrue(date != null);
   int i = date.setDateAsString("20081-12-30T12:15:45+02:00");
   assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE);
   assertTrue(date.getDateAsString().equals("2007-10-23T14:15:16+03:00"));
   i = date.setDateAsString("200-12-30T12:15:45+02:00");
   assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE);
   assertTrue(date.getDateAsString().equals("2007-10-23T14:15:16+03:00"));
   i = date.setDateAsString("");
   assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
   assertTrue(date.getDateAsString().equals("2000-01-01T00:00:00Z"));
   i = date.setDateAsString("2008-12-30T12:15:45+02:00");
   assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS);
   assertTrue(date.getYear() == 2008);
   assertTrue(date.getMonth() == 12);
   assertTrue(date.getDay() == 30);
   assertTrue(date.getHour() == 12);
   assertTrue(date.getMinute() == 15);
   assertTrue(date.getSecond() == 45);
   assertTrue(date.getSignOffset() == 1);
   assertTrue(date.getHoursOffset() == 2);
   assertTrue(date.getMinutesOffset() == 0);
   date = null;
 }
Ejemplo n.º 11
0
 /** parses standard date string. */
 @Test
 public void parse_standard() {
   Date date = Date.valueOf("1234-01-02", Date.Format.STANDARD);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Ejemplo n.º 12
0
 /** optionの解析。 */
 @Test
 public void parse_option() {
   StringOption option = new StringOption("20100615");
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2010));
   assertThat(date.getMonth(), is(6));
   assertThat(date.getDay(), is(15));
 }
Ejemplo n.º 13
0
 // convert to String in universal time format (HH:MM:SS)
 public String toUniversalString() {
   return String.format(
       "%02d/%02d/%04d - %02d:%02d:%02d",
       date.getMonth(),
       date.getDay(),
       date.getYear(),
       time.getHour(),
       time.getMinute(),
       time.getSecond());
 }
Ejemplo n.º 14
0
 public void draw() {
   int i;
   System.out.printf("ID:%d,Date:%d/%d/%d", ID, day.getYear(), day.getMonth(), day.getDate());
   System.out.println();
   System.out.print("Number:");
   for (i = 0; i < 6; i++) {
     System.out.printf("%d ", num[i]);
   }
   System.out.println();
 }
Ejemplo n.º 15
0
 // return DateAndTime string representation
 public String toString() {
   return String.format(
       "%02d/%02d/%04d - %02d:%02d:%02d %s",
       date.getMonth(),
       date.getDay(),
       date.getYear(),
       ((time.getHour() == 0 || time.getHour() == 12) ? 12 : time.getHour() % 12),
       time.getMinute(),
       time.getSecond(),
       (time.getHour() < 12 ? "AM" : "PM"));
 }
Ejemplo n.º 16
0
 /**
  * Get the first date attribute found as a string. If none are found return an empty string.
  *
  * @return the date string.
  */
 public String getYear() {
   for (final GedObject gedObject : getAttributes()) {
     if (!(gedObject instanceof Date)) {
       continue;
     }
     final Date attr = (Date) gedObject;
     if (!attr.getDate().isEmpty()) {
       return attr.getYear();
     }
   }
   return "";
 }
Ejemplo n.º 17
0
  public static Timestamp valueOf(String s) {
    String[] components = s.split(" ");
    if (components.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    String[] timeComponents = components[1].split("\\.");
    boolean hasNanos = true;
    int nanos = 0;

    if (timeComponents.length == 1) {
      // Allow timestamps without .fffffffff nanoseconds field
      hasNanos = false;
    } else if (timeComponents.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    Date d = Date.valueOf(components[0]);
    Time t = Time.valueOf(timeComponents[0]);
    if (hasNanos) {
      String nanosString = timeComponents[1];
      int len = nanosString.length();
      assert len > 0; // len must be > 0 if hasNanos is true
      if (len > 9) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }

      // Pad zeros on the right up to a total of 9 digits
      if (len < 9) {
        nanosString += "00000000".substring(len - 1);
      }

      try {
        nanos = Integer.valueOf(nanosString);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }
    }

    return new Timestamp(
        d.getYear(),
        d.getMonth(),
        d.getDate(),
        t.getHours(),
        t.getMinutes(),
        t.getSeconds(),
        nanos);
  }
Ejemplo n.º 18
0
  void checkCalendar(int start, int end) {
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    calendar.clear();

    calendar.set(Calendar.YEAR, start);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DATE, 1);

    Date date = new Date();
    date.setElapsedDays(DateUtil.getDayFromDate(start, 1, 1));
    while (calendar.get(Calendar.YEAR) <= end) {

      String calString = calendar.toString();
      assertThat("Year: " + calString, date.getYear(), is(calendar.get(Calendar.YEAR)));
      assertThat("Month: " + calString, date.getMonth(), is(calendar.get(Calendar.MONTH) + 1));
      assertThat("Date: " + calString, date.getDay(), is(calendar.get(Calendar.DATE)));

      calendar.add(Calendar.DATE, 1);
      date.setElapsedDays(date.getElapsedDays() + 1);
    }
  }
 public static int getDatesDifference(Date first, Date second) {
   return (first.getYear() - second.getYear()) * 365
       + (first.getMonth() - second.getMonth()) * 30
       + (first.getDay() - second.getDay());
 }
Ejemplo n.º 20
0
 public int getYear() {
   return date.getYear();
 }