Ejemplo n.º 1
0
  /**
   * Return the date of the next working day
   *
   * @return the date of the next working day
   */
  public static Date getNextWorkingDay() {
    Date nextWorkingDay = DateUtil.addDaysToDate(DateUtil.getSystemDate(), 1);
    Calendar c = Calendar.getInstance();
    c.setTime(nextWorkingDay);

    int day = c.get(Calendar.DAY_OF_WEEK);

    if (day == Calendar.SUNDAY) {
      nextWorkingDay = DateUtil.addDaysToDate(nextWorkingDay, 1);
    }

    return nextWorkingDay;
  }
Ejemplo n.º 2
0
 public void run() {
   Logger.println("Version " + Version.getAgentFullVersion());
   long dateUnit = DateUtil.getDateUnit();
   while (running) {
     reload(false);
     // Text Data Reset..
     long nowUnit = DateUtil.getDateUnit();
     if (dateUnit != nowUnit) {
       dateUnit = nowUnit;
       DataProxy.reset();
     }
     ThreadUtil.sleep(3000);
   }
 }
Ejemplo n.º 3
0
  public static long differTime(java.sql.Timestamp startTs, java.sql.Timestamp endTs) {
    String s1 = DateUtil.getDate(startTs, DATE_FORMAT_YYYYMMDD); // "2005-04-28";
    String s2 = DateUtil.getDate(endTs, DATE_FORMAT_YYYYMMDD); // "2005-04-28";
    // String s2 = "2005-04-20";

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    ParsePosition pos = new ParsePosition(0);
    ParsePosition pos1 = new ParsePosition(0);
    Date dt1 = formatter.parse(s1, pos);
    Date dt2 = formatter.parse(s2, pos1);
    long l = (dt1.getTime() - dt2.getTime()) / (3600 * 24 * 1000);

    // out.println("���?+l+"��");
    return l;
  }
Ejemplo n.º 4
0
 public void testCreateDate() {
   Date date = DateUtil.createDate(2000, 1, 1);
   Calendar calendar = new GregorianCalendar();
   calendar.setTime(date);
   assertEquals(2000, calendar.get(Calendar.YEAR));
   assertEquals(1, calendar.get(Calendar.MONTH));
   assertEquals(1, calendar.get(Calendar.DAY_OF_MONTH));
 }
Ejemplo n.º 5
0
 private Object getNumericCellValue(final Cell cell) {
   Object cellValue;
   if (DateUtil.isCellDateFormatted(cell)) {
     cellValue = new Date(cell.getDateCellValue().getTime());
   } else {
     cellValue = cell.getNumericCellValue();
   }
   return cellValue;
 }
Ejemplo n.º 6
0
  @Test
  public void testConvertStringToTimestamp() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);

    final Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4");
    final Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(time.getTime());
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
Ejemplo n.º 7
0
  @Test
  public void testConvertStringToDate() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);
    // test empty time
    Date date = (Date) converter.convert(Date.class, "");
    assertNull(date);
    date = (Date) converter.convert(Date.class, datePart);

    final Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
Ejemplo n.º 8
0
  /**
   * * 셀렉트 일 날짜 생성 ex(getDay(25))
   *
   * @param d : 현재 일
   * @return
   */
  public static String getSelDay(int sY, int sM, int sD) {
    StringBuffer dataList = new StringBuffer();

    String day = "";
    for (int i = 1; i <= DateUtil.getLastDay(sY, sM); i++) {

      day = zeroFill("00", Integer.toString(i));

      if (i == sD) {
        dataList.append("<option value='" + day + "' selected>" + day + "</option>");
      } else {
        dataList.append("<option value='" + day + "'>" + day + "</option>");
      }
    }

    return dataList.toString();
  }
Ejemplo n.º 9
0
  protected static void recordToErrorCounter(String cmd) {

    String today = DateUtil.format(new Date(), "yyyyMMdd");
    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today);

    } catch (Exception e) {

      logger.warn("记录api返回错误请求的次数失败, today: {}", today, e);
    }

    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today + ":cmd:" + cmd);

    } catch (Exception e) {

      logger.warn("记录cmd: {}, today: {} 返回错误请求的次数失败", cmd, today, e);
    }
  }
Ejemplo n.º 10
0
 @Test
 public void testConvertDateToString() throws Exception {
   final Calendar cal = new GregorianCalendar(2005, 0, 16);
   final String date = (String) converter.convert(String.class, cal.getTime());
   assertEquals(DateUtil.convertDateToString(cal.getTime()), date);
 }
Ejemplo n.º 11
0
 @Test
 public void testConvertTimestampToString() throws Exception {
   final Timestamp timestamp = Timestamp.valueOf("2005-03-10 01:02:03.4");
   final String time = (String) converter.convert(String.class, timestamp);
   assertEquals(DateUtil.getDateTime(DateUtil.getDateTimePattern(), timestamp), time);
 }
Ejemplo n.º 12
0
 public static String getShortDate(Date date, Locale locale) {
   DateFormat formatter = null;
   formatter = DateUtil.getShortDateFormat(locale);
   return formatter.format(date) + DateUtil.getZoneOffset(date, locale);
 }
Ejemplo n.º 13
0
 /**
  * Returns true if the String is a valid date by specifying the date format to be verified.
  *
  * @param strDate The date.
  * @param dateStrFormat The date format of the specified strDate
  * @return True, if it is a valid date. False, otherwise.
  */
 public static boolean isValidDate(String strDate, String dateStrFormat) {
   return DateUtil.toDate(strDate, dateStrFormat) != null;
 }
Ejemplo n.º 14
0
 /**
  * Returns true if the String is a valid date.
  *
  * @param strDate The date in format ddmmyyyy.
  * @return True, if it is a valid date. False, otherwise.
  */
 public static boolean isValidDate(String strDate) {
   return DateUtil.toDate(strDate, "ddMMyyyy") != null;
 }
Ejemplo n.º 15
0
 /**
  * This method convert the date to string
  *
  * @param date date
  * @param strFormat the string format
  * @return date as string format
  */
 public static String getDate(Date date, String strFormat) {
   return DateUtil.parseDate(date, strFormat);
 }
Ejemplo n.º 16
0
 public void tradeForTomorrow() throws Exception {
   tradeForDate(DateUtil.getGameTomorrow());
 }