예제 #1
1
  @Test
  public void testReadBandRasterData() {
    Date startDate = Calendar.getInstance().getTime();
    // Product product = new Product("name", "desc", 100, 200);
    File file =
        TestUtil.getTestFile(
            productsFolder + "SP04_HRI1_X__1O_20050605T090007_20050605T090016_DLR_70_PREU.BIL.ZIP");
    // File rasterFile = TestUtil.getTestFile(productsFolder + "mediumImage.tif");
    System.setProperty("snap.dataio.reader.tileWidth", "100");
    System.setProperty("snap.dataio.reader.tileHeight", "200");
    try {

      Product finalProduct = reader.readProductNodes(file, null);
      ProductData data = ProductData.createInstance(ProductData.TYPE_UINT16, 20000);
      data.setElemFloatAt(3, 5);
      reader.readBandRasterData(
          finalProduct.getBandAt(0), 2000, 2000, 100, 200, data, new NullProgressMonitor());
      assertNotEquals(0, data.getElemFloatAt(0));
      assertNotEquals(-1000, data.getElemFloatAt(0));
      assertNotEquals(0, data.getElemFloatAt(1999));
      assertNotEquals(-1000, data.getElemFloatAt(1999));
      assertNotEquals(5, data.getElemFloatAt(3));
      Date endDate = Calendar.getInstance().getTime();
      assertTrue(
          "The load time for the product is too big!",
          (endDate.getTime() - startDate.getTime()) / (60 * 1000) < 30);
    } catch (IOException e) {
      e.printStackTrace();
      assertTrue(e.getMessage(), false);
    }
  }
예제 #2
0
파일: Dates.java 프로젝트: Voos/portfolio
  public static int daysBetween(Date start, Date end) {
    int answer = 0;

    if (start.after(end)) {
      Date temp = start;
      start = end;
      end = temp;
    }

    Calendar c1 = Calendar.getInstance();
    c1.setTime(start);

    Calendar c2 = Calendar.getInstance();
    c2.setTime(end);

    while (c1.get(Calendar.YEAR) < c2.get(Calendar.YEAR)) {
      int dayOfYear = c1.get(Calendar.DAY_OF_YEAR);
      int daysInYear = c1.getActualMaximum(Calendar.DAY_OF_YEAR);

      answer += daysInYear - dayOfYear + 1;
      c1.set(Calendar.DATE, 1);
      c1.set(Calendar.MONDAY, Calendar.JANUARY);
      c1.add(Calendar.YEAR, 1);
    }

    answer += c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR);

    return answer;
  }
  @Test
  public void shouldParseAndyWarholArtistInfobox() throws MalformedURLException {

    Calendar birthDateCalendar = Calendar.getInstance();
    birthDateCalendar.set(1928, Calendar.AUGUST, 6, 0, 0, 0);
    birthDateCalendar.set(Calendar.MILLISECOND, 0);

    Calendar deathDateCalendar = Calendar.getInstance();
    deathDateCalendar.set(1987, Calendar.FEBRUARY, 22, 0, 0, 0);
    deathDateCalendar.set(Calendar.MILLISECOND, 0);

    Artist artist = WikipediaArtistInfoboxParser.parse(INFOBOX);

    Assert.assertEquals("Andy Warhol", artist.getName());
    Assert.assertEquals(
        new URL("https://en.wikipedia.org/wiki/File:Andy_Warhol_by_Jack_Mitchell.jpg"),
        artist.getImage());
    Assert.assertEquals(birthDateCalendar.getTimeInMillis(), artist.getBirthDate().getTime());
    Assert.assertEquals("Pittsburgh", artist.getBirthPlace().getName());
    Assert.assertEquals("Pennsylvania", artist.getBirthPlace().getState());
    Assert.assertEquals("United States", artist.getBirthPlace().getCountry());
    Assert.assertEquals(deathDateCalendar.getTimeInMillis(), artist.getDeathDate().getTime());
    Assert.assertEquals("New York City", artist.getDeathPlace().getName());
    Assert.assertEquals("New York", artist.getDeathPlace().getState());
    Assert.assertEquals("United States", artist.getDeathPlace().getCountry());
    Assert.assertEquals("American", artist.getNationality());
    Assert.assertEquals("Pop art", artist.getArtMovements().get(0).getName());
  }
  /**
   * This method is not thread safe. It has been modified from the original to not rely on global
   * time state. If a timestamp is in the future we return it as an absolute date string. Within the
   * same second we return 0s
   *
   * @param res resource
   * @param currentTimeMillis timestamp for offset
   * @param timestamp timestamp
   * @return the relative time string
   */
  static String getRelativeTimeString(Resources res, long currentTimeMillis, long timestamp) {
    final long diff = currentTimeMillis - timestamp;
    if (diff >= 0) {
      if (diff < DateUtils.MINUTE_IN_MILLIS) { // Less than a minute ago
        final int secs = (int) (diff / 1000);
        return res.getQuantityString(R.plurals.tw__time_secs, secs, secs);
      } else if (diff < DateUtils.HOUR_IN_MILLIS) { // Less than an hour ago
        final int mins = (int) (diff / DateUtils.MINUTE_IN_MILLIS);
        return res.getQuantityString(R.plurals.tw__time_mins, mins, mins);
      } else if (diff < DateUtils.DAY_IN_MILLIS) { // Less than a day ago
        final int hours = (int) (diff / DateUtils.HOUR_IN_MILLIS);
        return res.getQuantityString(R.plurals.tw__time_hours, hours, hours);
      } else {
        final Calendar now = Calendar.getInstance();
        now.setTimeInMillis(currentTimeMillis);
        final Calendar c = Calendar.getInstance();
        c.setTimeInMillis(timestamp);
        final Date d = new Date(timestamp);

        if (now.get(Calendar.YEAR) == c.get(Calendar.YEAR)) {
          // Same year
          RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_short));
        } else {
          // Outside of our year
          RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_long));
        }
        return RELATIVE_DATE_FORMAT.format(d);
      }
    }
    RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_long));
    return RELATIVE_DATE_FORMAT.format(new Date(timestamp));
  }
예제 #5
0
파일: Exam.java 프로젝트: Hex-s/java
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    // 查找2010年到当前年份间上牌的车辆信息

    // 汽车的上牌时间
    Calendar cardDate;

    // 当前年份的时间
    Calendar afterDate = Calendar.getInstance();
    // 2010年的时间
    Calendar beforeDate = Calendar.getInstance();
    beforeDate.set(Calendar.YEAR, 2010);

    //		if(cardDate.after(beforeDate) && cardDate.before(afterDate)){
    //
    //		}

    //		上牌时间 2010.5.4 17:30
    //		起始时间 2010.8.13 11:52
    // 根据经历过的总毫秒值进行判断
    //		if(cardDate.getTimeInMillis() >= beforeDate.getTimeInMillis() && cardDate.getTimeInMillis()
    // <= afterDate.getTimeInMillis()){
    //
    //		}

  }
  private void startTrackingService() {
    if (!DateTimes.isSameDay(mDate, Calendar.getInstance())) {
      mDate = Calendar.getInstance();

      TextView txtDate = (TextView) findViewById(R.id.txtDate);
      txtDate.setText(DateTimes.dateFormat().format(mDate));

      GPSHelper.loadTrackings(mDate);
      updateList();
    }

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(PresenceManagerUtil.CHANGE_STATUS);
    getApplicationContext().registerReceiver(mIspReceiver, intentFilter);

    mPresenceManager.startPresence();
    for (String p : mLocationManager.getAllProviders()) {
      LocationListener ll = new MyLocationListener();
      mLocationManager.requestLocationUpdates(
          p, 60000, // 通知のための最小時間間隔(ミリ秒)
          30, // 通知のための最小距離間隔(メートル)
          ll);
      locationListeners.add(ll);
    }
    buttonVisible(true);
  }
예제 #7
0
 @Test
 public void testReadProductNodes() {
   Date startDate = Calendar.getInstance().getTime();
   Product product = new Product("name", "desc", 100, 100);
   File file =
       TestUtil.getTestFile(
           productsFolder + "SP04_HRI1_X__1O_20050605T090007_20050605T090016_DLR_70_PREU.BIL.ZIP");
   System.setProperty("snap.dataio.reader.tileWidth", "100");
   System.setProperty("snap.dataio.reader.tileHeight", "100");
   try {
     Product finalProduct = reader.readProductNodes(file, null);
     assertEquals(4, finalProduct.getBands().length);
     assertEquals("WGS84(DD)", finalProduct.getSceneGeoCoding().getGeoCRS().getName().toString());
     assertEquals("SPOTView", finalProduct.getProductType());
     assertEquals(0, finalProduct.getMaskGroup().getNodeCount());
     assertEquals(2713, finalProduct.getSceneRasterWidth());
     assertEquals(2568, finalProduct.getSceneRasterHeight());
     Date endDate = Calendar.getInstance().getTime();
     assertTrue(
         "The load time for the product is too big!",
         (endDate.getTime() - startDate.getTime()) / (60 * 1000) < 30);
   } catch (IOException e) {
     e.printStackTrace();
     assertTrue(e.getMessage(), false);
   }
 }
  @Test
  public void testDoSendFailsWithInvalidTime() throws Exception {
    IntegrationDefinition integrationDefinition =
        new IntegrationDefinition("test", providerService, consumerSystem, 5000, true, null, null);

    EgovWebService service = new EgovWebService("test", 5000, integrationDefinition, echoClient);

    Calendar from = Calendar.getInstance();
    from.add(Calendar.YEAR, 1);
    Calendar to = Calendar.getInstance();
    to.add(Calendar.YEAR, -1);

    // from
    integrationDefinition.setValidateFrom(from);
    integrationDefinition.setValidateTo(null);

    EgovIntegrationMessage requestMessage = service.createRequestMessage();
    EgovIntegrationMessage responseMessage = service.doSend(requestMessage);

    assertNotNull(responseMessage);
    assertNotNull(responseMessage.getHeader());
    assertEquals(ResultCode.INVALID_TIME, responseMessage.getHeader().getResultCode());

    // to
    integrationDefinition.setValidateFrom(null);
    integrationDefinition.setValidateTo(to);

    requestMessage = service.createRequestMessage();
    responseMessage = service.doSend(requestMessage);

    assertNotNull(responseMessage);
    assertNotNull(responseMessage.getHeader());
    assertEquals(ResultCode.INVALID_TIME, responseMessage.getHeader().getResultCode());
  }
예제 #9
0
 public static boolean isOlderThanAge18(String paramString) {
   if (!isIdCardNo(paramString)) {}
   int j;
   int k;
   do {
     int i;
     do {
       int m;
       int n;
       do {
         return false;
         i = paramString.length();
         if (18 != i) {
           break;
         }
         m = Integer.valueOf(paramString.substring(6, 10)).intValue();
         n = Calendar.getInstance().get(1);
       } while (m + 18 >= n);
       return true;
     } while (15 != i);
     j = 1900 + Integer.valueOf(paramString.substring(6, 8)).intValue();
     k = Calendar.getInstance().get(1);
   } while (j + 18 >= k);
   return true;
 }
  private void configureDateTimePicker() {
    Calendar newCalendar = Calendar.getInstance();
    final Calendar newDate = Calendar.getInstance();

    // Launch Time Picker Dialog
    mTimePickerDialog =
        new TimePickerDialog(
            mThis,
            new TimePickerDialog.OnTimeSetListener() {
              @Override
              public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                newDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
                newDate.set(Calendar.MINUTE, minute);
                mTxtDueDate.setText(
                    Utils.formatDate(
                        mThis, newDate.getTime(), R.string.schedule_format_date_and_time));
              }
            },
            newCalendar.get(Calendar.HOUR_OF_DAY),
            newCalendar.get(Calendar.MINUTE),
            true);

    fromDatePickerDialog =
        new DatePickerDialog(
            this,
            new DatePickerDialog.OnDateSetListener() {
              public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                newDate.set(year, monthOfYear, dayOfMonth);
                mTimePickerDialog.show();
              }
            },
            newCalendar.get(Calendar.YEAR),
            newCalendar.get(Calendar.MONTH),
            newCalendar.get(Calendar.DAY_OF_MONTH));
  }
  @Override
  public boolean doPostUpdateCredential(
      String userName, Object credential, UserStoreManager userStoreManager)
      throws UserStoreException {

    IdentityMgtConfig config = IdentityMgtConfig.getInstance();

    UserIdentityClaimsDO userIdentityDTO = module.load(userName, userStoreManager);

    if (userIdentityDTO == null) {
      userIdentityDTO = new UserIdentityClaimsDO(userName);
    }

    // Do not timestamp if OTP enabled.
    boolean userOTPEnabled = userIdentityDTO.getOneTimeLogin();

    if (config.isAuthPolicyExpirePasswordCheck()
        && !userOTPEnabled
        && (!userStoreManager.isReadOnly())) {

      Calendar currentTime = Calendar.getInstance();
      userIdentityDTO.setPasswordTimeStamp(Calendar.getInstance().getTimeInMillis());

      try {
        // Store the new timestamp after change password
        module.store(userIdentityDTO, userStoreManager);

      } catch (IdentityException e) {
        throw new UserStoreException(e.getMessage());
      }
    }

    return true;
  }
예제 #12
0
  /**
   * Is borrow expired = now is later than maximumReturnDate
   *
   * @return
   */
  public boolean getIsBorrowExpired() {
    Calendar ret = Calendar.getInstance(), now = Calendar.getInstance();
    ret.setTime(getMaximumReturnDate());

    if (ret.compareTo(now) < 0) return true;
    else return false;
  }
예제 #13
0
  private void recordStatistics(int state) {
    if (metricsBean == null) {
      return;
    }

    switch (state) {
      case ST_ACTIVE:
        metricsBean.resetConsecutiveSuspensions();
        metricsBean.resetConsecutiveTimeouts();
        metricsBean.setSuspendedAt(null);
        metricsBean.setTimedoutAt(null);
        break;

      case ST_TIMEOUT:
        metricsBean.resetConsecutiveSuspensions();
        metricsBean.incrementTimeouts();
        if (localState != ST_TIMEOUT) {
          metricsBean.setTimedoutAt(Calendar.getInstance().getTime());
          metricsBean.setSuspendedAt(null);
        }
        break;

      case ST_SUSPENDED:
        metricsBean.resetConsecutiveTimeouts();
        metricsBean.incrementSuspensions();
        if (localState != ST_SUSPENDED) {
          metricsBean.setSuspendedAt(Calendar.getInstance().getTime());
          metricsBean.setTimedoutAt(null);
        }
        break;
    }
  }
예제 #14
0
파일: Dates.java 프로젝트: Voos/portfolio
 public static boolean isSameMonth(Date current, Date date) {
   Calendar c1 = Calendar.getInstance();
   Calendar c2 = Calendar.getInstance();
   c1.setTime(current);
   c2.setTime(date);
   return c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
 }
예제 #15
0
public class DateIterator implements Iterator<Date>, Iterable<Date> {

  private Calendar end = Calendar.getInstance();
  private Calendar current = Calendar.getInstance();

  public DateIterator(Date start, Date end) {
    this.end.setTime(end);
    this.end.add(Calendar.DATE, -1);
    this.current.setTime(start);
    this.current.add(Calendar.DATE, -1);
  }

  public boolean hasNext() {
    return !current.after(end);
  }

  public Date next() {
    current.add(Calendar.DATE, 1);
    return current.getTime();
  }

  public void remove() {
    throw new UnsupportedOperationException("Cannot remove");
  }

  public Iterator<Date> iterator() {
    return this;
  }
}
  private List<Long> getPayUsers(Calendar calendar) {
    List<Long> payUserIds = new ArrayList<Long>();

    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTime(calendar.getTime());
    calendar1.set(Calendar.HOUR_OF_DAY, 0);
    calendar1.set(Calendar.MINUTE, 0);
    calendar1.set(Calendar.SECOND, 0);

    Calendar calendar2 = Calendar.getInstance();
    calendar2.setTime(calendar.getTime());
    calendar2.set(Calendar.HOUR_OF_DAY, 23);
    calendar2.set(Calendar.MINUTE, 59);
    calendar2.set(Calendar.SECOND, 59);
    try {
      PreparedStatement pstmt =
          orderCon.prepareStatement(
              "select distinct(uid) from ordersqq where time between ? and ? and cmd=7");
      pstmt.setLong(1, calendar1.getTimeInMillis());
      pstmt.setLong(2, calendar2.getTimeInMillis());
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        payUserIds.add(rs.getLong(1));
      }
    } catch (Exception e) {
      logger.error("", e);
    }

    return payUserIds;
  }
예제 #17
0
  private long
      TimeDifference() { // need to check the alaram time and the triggring action time around 12

    Calendar cal = Calendar.getInstance();
    Log.d("settings.java ", " time before setting :" + cal.getTime());
    Log.d("settings.java ", " calendertime in millisec: " + cal.getTimeInMillis());
    Log.d("settings.java ", " system time in millisec :" + System.currentTimeMillis());

    // cal.setTime();

    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    // cal.set(Calendar.HOUR, 23);
    cal.set(Calendar.MINUTE, 0);
    cal.add(Calendar.DAY_OF_MONTH, 1);

    Log.d("settings.java", " time After setting day+1 and 00 hours :" + cal.getTime());

    Log.d("settings.java", " set time in millis :" + cal.getTimeInMillis());
    Log.d(
        "settings.java",
        " time of the system in millis" + Calendar.getInstance().getTimeInMillis());

    long timediff = cal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(); // +1000;

    Log.d(
        "settings.java",
        " current time: "
            + Calendar.getInstance()
            + " setted time in alaram should be 23.59.59 but is : "
            + cal.getTime()
            + "time diff in millisec :"
            + timediff);
    return timediff;
  }
예제 #18
0
 private void updateDate() {
   StringBuffer timer = new StringBuffer();
   timer.append(Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
   timer.append(":" + Calendar.getInstance().get(Calendar.MINUTE));
   timer.append(":" + Calendar.getInstance().get(Calendar.SECOND));
   curTimeTxt.setText(timer.toString());
 }
  @Test
  public void checkBooking() throws CabNotAvailableException {
    Cab one = new Cab("DL01HB001", 100020);
    Cab two = new Cab("DL01HB002", 100040);
    Cab three = new Cab("DL01HB003", 100060);
    Cab four = new Cab("DL01HB004", 100080);

    ICabBookingSystem system = new CabBookingSystemImpl();
    system.addCab(one);
    system.addCab(two);
    system.addCab(three);
    system.addCab(four);

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 10);
    String cab = system.requestForCab(new CabRequest("BR001", 100025, 100056, cal.getTime()));
    Assert.assertEquals(cab, "DL01HB001");

    cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 11);
    cab = system.requestForCab(new CabRequest("BR002", 100056, 100022, cal.getTime()));
    Assert.assertEquals(cab, "DL01HB003");

    cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 15);
    cab = system.requestForCab(new CabRequest("BR003", 100020, 100075, cal.getTime()));
    Assert.assertEquals(cab, "DL01HB003");

    cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 15);
    cab = system.requestForCab(new CabRequest("BR004", 100040, 100056, cal.getTime()));
    Assert.assertEquals(cab, "DL01HB002");
  }
예제 #20
0
  /**
   * 获取智能生日
   *
   * @param birthday
   * @param needYear
   * @return
   */
  public static String getSmartBirthday(long birthday, boolean needYear) {
    int[] birthdayDetails = getDateDetail(birthday);
    int[] nowDetails = getDateDetail(System.currentTimeMillis());

    Calendar birthdayCalendar = Calendar.getInstance();
    birthdayCalendar.set(birthdayDetails[0], birthdayDetails[1], birthdayDetails[2]);

    Calendar nowCalendar = Calendar.getInstance();
    nowCalendar.set(nowDetails[0], nowDetails[1], nowDetails[2]);

    int days = birthdayCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR);
    if (days < 8) {
      if (days >= 3) {
        return days + "天后";
      }
      if (days >= 2) {
        return TimeUtil.Day.NAME_THE_DAY_AFTER_TOMORROW;
      }
      if (days >= 1) {
        return TimeUtil.Day.NAME_TOMORROW;
      }
      if (days >= 0) {
        return TimeUtil.Day.NAME_TODAY;
      }
    }

    if (needYear) {
      return birthdayDetails[0] + "年" + birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
    }
    return birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
  }
예제 #21
0
  public String getDisplayDateString() {
    Calendar now = Calendar.getInstance();
    Calendar posted = Calendar.getInstance();
    posted.setTime(date);

    int nowDay = now.get(Calendar.DAY_OF_YEAR);
    int postedDay = posted.get(Calendar.DAY_OF_YEAR);

    int diff = nowDay - postedDay;

    StringBuilder sb = new StringBuilder();
    if (diff == 0) {
      sb.append("Posted today");
    } else if (diff == 1) {
      sb.append("Posted yesterday");
    } else {
      sb.append("Posted ");
      sb.append(diff);
      sb.append(" days ago");
    }
    sb.append(" (");
    sb.append(DISPLAY_DATE_FORMAT.format(date));
    sb.append(")");

    return sb.toString();
  }
예제 #22
0
 // TODO check if minimum required fields are set?
 @Override
 public int sendMail() {
   int sendResult = -999;
   if (mail != null) {
     LOGGER.trace(
         "Sending Mail: \nfrom = '"
             + mail.getFrom()
             + "'\n"
             + "replyTo='"
             + mail.getTo()
             + "'\n"
             + "\n"
             + mail);
     MailSenderPluginApi mailPlugin =
         (MailSenderPluginApi) getContext().getWiki().getPluginApi("mailsender", getContext());
     sendResult = mailPlugin.sendMail(mail, getMailConfiguration());
     LOGGER.info(
         "Sent Mail from '"
             + mail.getFrom()
             + "' to '"
             + mail.getTo()
             + "'. Result was '"
             + sendResult
             + "'. Time: "
             + Calendar.getInstance().getTimeInMillis());
   } else {
     LOGGER.info(
         "Mail Object is null. Send result was '"
             + sendResult
             + "'. Time: "
             + Calendar.getInstance().getTimeInMillis());
   }
   return sendResult;
 }
  protected static String getTimeAgoString(
      Locale locale, long timestamp, boolean isMultiple, TimeAgoType timeAgoType) {
    if (timeAgoType == TimeAgoType.DIFF) {
      long now = System.currentTimeMillis();
      float diff = now - timestamp;
      String stime = getShortTimestamp(diff);
      return stime;
    } else {
      if (timeAgoType == TimeAgoType.PREFER_DATE_TIME && !isMultiple) {
        return getBuildTimeString(timestamp, locale, true, true, true);
      } else {
        Calendar nowCal = Calendar.getInstance();
        nowCal.setTimeInMillis(System.currentTimeMillis());
        Calendar thenCal = Calendar.getInstance();
        thenCal.setTimeInMillis(timestamp);

        int nowDay = nowCal.get(Calendar.DAY_OF_YEAR);
        int thenDay = thenCal.get(Calendar.DAY_OF_YEAR);

        boolean isToday = (nowDay == thenDay);
        if (isToday) {
          return getBuildTimeString(timestamp, locale, false, true, false);
        } else {
          return getBuildTimeString(timestamp, locale, true, false, false);
        }
      }
    }
  }
예제 #24
0
  /** Make an update for the daily/weekly/last kill & ap counts */
  public void doUpdate() {
    boolean needUpdate = false;
    Calendar lastCal = Calendar.getInstance();
    lastCal.setTimeInMillis(lastUpdate);

    Calendar curCal = Calendar.getInstance();
    curCal.setTimeInMillis(System.currentTimeMillis());

    // Checking the day - month & year are checked to prevent if a player come back after 1 month,
    // the same day
    if (lastCal.get(Calendar.DAY_OF_MONTH) != curCal.get(Calendar.DAY_OF_MONTH)
        || lastCal.get(Calendar.MONTH) != curCal.get(Calendar.MONTH)
        || lastCal.get(Calendar.YEAR) != curCal.get(Calendar.YEAR)) {
      this.dailyAP = 0;
      this.dailyKill = 0;
      needUpdate = true;
    }

    // Checking the week - year is checked to prevent if a player come back after 1 year, the same
    // week
    if (lastCal.get(Calendar.WEEK_OF_YEAR) != curCal.get(Calendar.WEEK_OF_YEAR)
        || lastCal.get(Calendar.YEAR) != curCal.get(Calendar.YEAR)) {
      this.lastKill = this.weeklyKill;
      this.lastAP = this.weeklyAP;
      this.weeklyKill = 0;
      this.weeklyAP = 0;
      needUpdate = true;
    }

    // Finally, update the the last update
    this.lastUpdate = System.currentTimeMillis();

    if (needUpdate) setPersistentState(PersistentState.UPDATE_REQUIRED);
  }
예제 #25
0
 /**
  * We override setValues to compute locally everything we need
  *
  * @param idx The index of the attribute to modify.
  * @param value The new attribute value.
  */
 public void setValue(int idx, Object value) {
   super.setValue(idx, value);
   if (idx == ATTR_DATE_START) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(((Long) value).longValue()));
     a_year = cal.get(Calendar.YEAR);
     a_month = cal.get(Calendar.MONTH);
     a_week = cal.get(Calendar.DAY_OF_WEEK);
     a_day = cal.get(Calendar.DAY_OF_MONTH);
     a_time =
         cal.get(Calendar.HOUR_OF_DAY) * 3600
             + cal.get(Calendar.MINUTE) * 60
             + cal.get(Calendar.SECOND);
   } else if (idx == ATTR_DATE_END) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(((Long) value).longValue()));
     b_year = cal.get(Calendar.YEAR);
     b_month = cal.get(Calendar.MONTH);
     b_week = cal.get(Calendar.DAY_OF_WEEK);
     b_day = cal.get(Calendar.DAY_OF_MONTH);
     b_time =
         cal.get(Calendar.HOUR_OF_DAY) * 3600
             + cal.get(Calendar.MINUTE) * 60
             + cal.get(Calendar.SECOND);
   }
 }
  private void initializeCalendar() {

    calendario.setOnDateChangedListener(listener);
    calendario.setShowOtherDates(MaterialCalendarView.SHOW_ALL);

    Calendar calendar = Calendar.getInstance();
    calendario.setSelectedDate(calendar.getTime());

    /*calendar.set(calendar.get(Calendar.YEAR), Calendar.JANUARY, 1);
    calendario.setMinimumDate(calendar.getTime());

    calendar.set(calendar.get(Calendar.YEAR), Calendar.DECEMBER, 31);
    calendario.setMaximumDate(calendar.getTime());*/

    calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -2);

    OneDayDecorator diaDecor = new OneDayDecorator();

    ArrayList<CalendarDay> dates = new ArrayList<>();
    CalendarDay cal = CalendarDay.from(calendar);

    dates.add(cal);

    // calendario.addDecorator(new EventDecorator(0xffcccccc, dates));
    diaDecor.setDate(new Date(calendar.getTimeInMillis()));
    calendario.addDecorator(diaDecor);
  }
예제 #27
0
 /**
  * True if the time is this year.
  *
  * @param time the time
  */
 private static boolean isThisYear(long time) {
   Calendar now = Calendar.getInstance();
   Calendar calendar = Calendar.getInstance();
   now.setTimeInMillis(System.currentTimeMillis());
   calendar.setTimeInMillis(time);
   return now.get(Calendar.YEAR) == calendar.get(Calendar.YEAR);
 }
예제 #28
0
  /*
   * dateStrings[0] = TODAY_TEXT
   * dateStrings[1] = YESTERDAY_TEXT
   */
  public static String getNiceTimeString(Calendar cal) {
    final String[] dateText = CityAlarmApplication.getAppResources().dateText;

    Calendar calNow = Calendar.getInstance();

    Calendar calTime = Calendar.getInstance();
    calTime.setTimeInMillis(cal.getTimeInMillis());

    // check for today and yesterday
    boolean isToday = false;
    boolean isYesterday = false;

    if (calNow.get(Calendar.YEAR) == calTime.get(Calendar.YEAR)) {
      if (calNow.get(Calendar.DAY_OF_YEAR) == calTime.get(Calendar.DAY_OF_YEAR)) isToday = true;
    }

    calNow.add(Calendar.DAY_OF_YEAR, -1);

    if (calNow.get(Calendar.YEAR) == calTime.get(Calendar.YEAR)) {
      if (calNow.get(Calendar.DAY_OF_YEAR) == calTime.get(Calendar.DAY_OF_YEAR)) isYesterday = true;
    }

    String text = Utils.getTimeString(calTime);

    if (isToday) {
      text = dateText[0] + ", " + Utils.getTimeOnlyString(calTime);
    }

    if (isYesterday) {
      text = dateText[1] + ", " + Utils.getTimeOnlyString(calTime);
    }

    return text;
  }
  protected Object getControlObject() {
    Vector responsibilities = new Vector();

    Calendar cal1 = Calendar.getInstance();
    cal1.clear();
    cal1.set(Calendar.MONTH, Calendar.JANUARY);
    cal1.set(Calendar.DAY_OF_MONTH, 1);
    cal1.set(Calendar.YEAR, 2001);

    Calendar cal2 = Calendar.getInstance();
    cal2.clear();
    cal2.set(Calendar.MONTH, Calendar.DECEMBER);
    cal2.set(Calendar.DAY_OF_MONTH, 27);
    cal2.set(Calendar.YEAR, 2004);

    Calendar cal3 = Calendar.getInstance();
    cal3.clear();
    cal3.set(Calendar.MONTH, Calendar.MAY);
    cal3.set(Calendar.DAY_OF_MONTH, 6);
    cal3.set(Calendar.YEAR, 2002);

    responsibilities.addElement(cal1);
    responsibilities.addElement(cal2);
    responsibilities.addElement(cal3);

    Employee employee = new Employee();
    employee.setID(CONTROL_ID);
    employee.setResponsibilities(responsibilities);
    return employee;
  }
  @Test
  public void shouldUseOnlyOneDirectionMapping() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .fieldAToB("name", "fullName")
        .field("age", "currentAge")
        .field("birthDate", "birthDate")
        .register();

    BasicPerson bpSrc = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());

    BasicPersonDto bpDtoSrc = new BasicPersonDto();
    bpDtoSrc.setFullName("Jan");
    bpDtoSrc.setCurrentAge(20);
    bpDtoSrc.setBirthDate(Calendar.getInstance().getTime());

    // when
    BoundMapperFacade<BasicPerson, BasicPersonDto> boundMapper =
        mapperFactory.getMapperFacade(BasicPerson.class, BasicPersonDto.class);

    BasicPersonDto bpDtoDest = boundMapper.map(bpSrc);
    BasicPerson bpDest = boundMapper.mapReverse(bpDtoSrc);

    // then
    assertThat(bpDtoDest.getCurrentAge()).isEqualTo(bpSrc.getAge());
    assertThat(bpDtoDest.getFullName()).isEqualTo(bpSrc.getName());
    assertThat(bpDtoDest.getBirthDate()).isEqualTo(bpSrc.getBirthDate());

    assertThat(bpDest.getAge()).isEqualTo(bpDtoSrc.getCurrentAge());
    assertThat(bpDest.getName()).isNull();
    assertThat(bpDest.getBirthDate()).isEqualTo(bpDtoSrc.getBirthDate());
  }