コード例 #1
0
 private Timestamp getScaledCurrentTimestamp(Timestamp time) {
   assert (this.clientStartTime != null);
   tmp_now.setTime(System.currentTimeMillis());
   time.setTime(
       AuctionMarkUtil.getScaledTimestamp(this.loaderStartTime, this.clientStartTime, tmp_now));
   if (LOG.isTraceEnabled())
     LOG.trace(
         String.format(
             "Scaled:%d / Now:%d / BenchmarkStart:%d / ClientStart:%d",
             time.getTime(),
             tmp_now.getTime(),
             this.loaderStartTime.getTime(),
             this.clientStartTime.getTime()));
   return (time);
 }
コード例 #2
0
  /**
   * Gets the timestamp for the scene and creates a label on the panel that displays the timestamp
   *
   * @return
   */
  private JLabel addSceneTimeTextToPanel() {
    JLabel label = new JLabel();
    if (scene.hasSceneTs()) {
      DateFormat formatter = I18N.getDateTimeFormatter();
      label.setText(formatter.format(scene.getSceneTs()));
    } else {
      // Add the date of scenes with relative dates to the panel
      if (scene.hasRelativeScene()) {
        BookModel model = mainFrame.getBookModel();
        Session session = model.beginTransaction();
        SceneDAOImpl dao = new SceneDAOImpl(session);
        // Get all scenes from the book
        Scene relative = dao.findRealtiveScene(scene.getRelativeSceneId());
        session.close();
        // Create the timestamp for the relative date
        Timestamp ts = relative.getSceneTs();
        Calendar cal = Calendar.getInstance();
        cal.setTime(ts);
        cal.add(Calendar.DAY_OF_WEEK, scene.getRelativeDateDifference());
        ts.setTime(cal.getTime().getTime());
        DateFormat formatter = I18N.getDateTimeFormatter();
        label.setText("[" + formatter.format(ts) + "]");
      }
    }

    return label;
  }
コード例 #3
0
ファイル: TimeMachine.java プロジェクト: kch0217/COMP3111Old
  public static void setTimeMac(
      int cyear, int cmonth, int cday, int chour, int cminute, int csecond) {

    currentTime.setTime(
        (new Timestamp(cyear - 1900, cmonth - 1, cday, chour, cminute, csecond, 0).getTime()));
    if (parent != null) {
      //			System.out.println("HI");
      parent.UpdateCal();
    }
  }
コード例 #4
0
 public void set(Timestamp t) {
   if (t == null) {
     timestamp.setTime(0);
     timestamp.setNanos(0);
     return;
   }
   this.timestamp = t;
   bytesEmpty = true;
   timestampEmpty = false;
 }
コード例 #5
0
 public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
   boolean hasDecimalOrSecondVInt = hasDecimalOrSecondVInt(bytes[offset]);
   long seconds = (long) TimestampWritable.getSeconds(bytes, offset);
   int nanos = 0;
   if (hasDecimalOrSecondVInt) {
     nanos = TimestampWritable.getNanos(bytes, offset + 4);
     if (hasSecondVInt(bytes[offset + 4])) {
       seconds +=
           LazyBinaryUtils.readVLongFromByteArray(
               bytes, offset + 4 + WritableUtils.decodeVIntSize(bytes[offset + 4]));
     }
   }
   t.setTime(seconds * 1000);
   if (nanos != 0) {
     t.setNanos(nanos);
   }
 }
コード例 #6
0
  /**
   * Returns a formatted string that indicates the last time a Ticket was worked on (in other words,
   * the date of the last annotation)
   */
  public static String getLastActivity(int ticketNumber) {
    DBHelper db = DBHelperFactory.createDBHelper();
    ArrayList<Annotation> annos = db.createAnnotationArrayListByTicket(ticketNumber);

    java.sql.Timestamp lastActivity = new java.sql.Timestamp(0L);

    for (int i = 0; i < annos.size(); i++) {
      java.sql.Timestamp ts = annos.get(i).getCreatedOn();

      if (ts.after(lastActivity)) {
        lastActivity.setTime(ts.getTime());
      }
    }

    String result = getTime(lastActivity);

    db.close();
    return result;
  }
コード例 #7
0
  public ByteArrayOutputStream getReportCode() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Document document = new Document(PageSize.B4, 40, 200, 120, 20);
    try {
      PdfWriter writer = PdfWriter.getInstance(document, baos);
      MyPageEvents events = new MyPageEvents();
      writer.setPageEvent(events);
      document.open();
      if (data.size() == 0) {
        PdfPTable table = new PdfPTable(1);
        table.addCell(printStr("", 6, 8, false, PdfPCell.NO_BORDER, 0));
        document.add(table);
      }
      PdfPTable table = new PdfPTable(1);
      table.setWidthPercentage(100);

      int border = 0;

      // Receipt Infos
      String row[] = (String[]) data.get(0);
      table.addCell(printStr("", 1, 18, false, border, 1));

      table.addCell(printStr(row[17], 1, 22, false, border, 1));
      table.addCell(printStr(" ", 1, 18, false, border, 1));
      table.addCell(printStr(" ", 1, 18, false, border, 1));

      table.addCell(printStr("Name: " + row[0], 1, 22, false, border, 0));
      table.addCell(printStr("      " + row[13], 1, 22, false, border, 0));
      table.addCell(printStr("Sex: " + row[14], 1, 22, false, border, 0));
      table.addCell(printStr("DOB: " + row[15], 1, 22, false, border, 0));

      if (row[12].equals("A"))
        table.addCell(
            printStr(
                "Nationality: " + GeneralDataInHtml.getCountryName(row[2]),
                1,
                22,
                false,
                border,
                0));
      table.addCell(printStr("PPT/Ref. No.: " + row[1], 1, 22, false, border, 0));

      table.addCell(printStr(" ", 1, 18, false, border, 1));
      table.addCell(printStr(" ", 1, 18, false, border, 1));
      double cashTotal = 0;
      double chequeTotal = 0;
      table.addCell(printStr(row[3] + "  x  " + row[4] + "  @$" + row[5], 1, 22, false, border, 0));
      for (int i = 1; i < data.size(); i++) {
        String item[] = (String[]) data.get(i);
        table.addCell(
            printStr(item[3] + "  x  " + item[4] + "  @$" + item[5], 1, 22, false, border, 0));
      }
      table.addCell(printStr(" ", 1, 18, false, border, 1));
      table.addCell(printStr(" ", 1, 18, false, border, 1));

      double amt = Double.parseDouble(row[9]);
      if (row[7].equals("cash")) {
        table.addCell(printStr("Cash Total: HK$" + amt + "0", 1, 22, false, border, 0));
      } else {
        table.addCell(printStr("Cheque: HK$" + amt + "0", 1, 22, false, border, 0));
        table.addCell(printStr("--" + row[8], 1, 22, false, border, 0));
      }
      table.addCell(printStr(" ", 1, 18, false, border, 1));

      // Count Collection Date
      Connection conn = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      int dayAdd = 2;
      int dayCount = 2;
      // int receiptDate = Integer.parseInt(row[18]);
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
      java.util.Date rDate = sdf.parse(row[18]);
      java.sql.Timestamp receiptDate = new java.sql.Timestamp(rDate.getTime());
      // 86400000 milliseconds in a day
      long oneDay = 1 * 24 * 60 * 60 * 1000;

      try {
        conn = JdbcConnection.getConnection();

        for (int k = 1; k <= dayCount; k++) {
          receiptDate.setTime(receiptDate.getTime() + oneDay);

          // System.out.println("select 1 from holiday where date = "+(receiptDate));
          ps = conn.prepareStatement("select 1 from holiday where date = ?");
          ps.setTimestamp(1, receiptDate);
          rs = ps.executeQuery();
          if (rs.next()) {
            dayCount += 1;
            dayAdd += 1;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (rs != null)
          try {
            rs.close();
          } catch (Exception e) {
            e.printStackTrace();
          }
        if (ps != null)
          try {
            ps.close();
          } catch (Exception e) {
            e.printStackTrace();
          }
        if (conn != null)
          try {
            conn.close();
          } catch (Exception e) {
            e.printStackTrace();
          }
      }

      Calendar cal = Calendar.getInstance();
      cal.set(
          Integer.parseInt(row[18].substring(0, 4)),
          Integer.parseInt(row[18].substring(4, 6)) - 1,
          Integer.parseInt(row[18].substring(6)));
      cal.add(cal.DATE, dayAdd);

      Date date = cal.getTime();
      SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy (EEE)", Locale.US);

      table.addCell(printStr(" ", 1, 18, false, border, 1));
      if (row[12].equals("A")) {
        table.addCell(printStr("Collection Date: " + df.format(date), 1, 22, false, border, 1));
        table.addCell(printStr("Collection Time: 4:00pm to 5:00pm", 1, 22, false, border, 1));
        table.addCell(printStr(" ", 1, 22, false, border, 1));
        table.addCell(printStr(row[10] + " " + row[16], 1, 22, false, border, 1));
        table.addCell(printStr(" ", 1, 22, false, border, 1));
        table.addCell(
            printStr(
                "APPLICATION IS SUBJECTED TO APPROVAL, PLEASE BRING THIS RECEIPT ON COLLECTION DAY",
                1,
                22,
                false,
                border,
                1));
        table.addCell(printStr(row[11], 1, 32, false, border, 1));
        table.addCell(printStr("(" + this.params + ")", 1, 22, false, border, 2));

      } else {
        table.addCell(printStr("THANK YOU", 1, 22, false, border, 1));
        table.addCell(printStr(row[10] + "   " + row[16], 1, 22, false, border, 1));
        table.addCell(printStr(" ", 1, 22, false, border, 1));
        table.addCell(printStr(row[11], 1, 22, false, border, 1));
        table.addCell(printStr("(" + this.params + ")", 1, 22, false, border, 2));
      }

      float[] widths4 = {10};
      table.setWidths(widths4);
      document.add(table);
      document.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return baos;
  }
コード例 #8
0
ファイル: TsTask.java プロジェクト: romanm/tcmoped14
 public void setTime(long time) {
   ts.setTime(time);
 }
コード例 #9
0
ファイル: TimeMachine.java プロジェクト: kch0217/COMP3111Old
  @Override
  public void run() { // thread content
    // TODO Auto-generated method stub
    if (timerfirst) { // lock by the first thread executing it
      timerfirst = false;
      while (true) {
        while (!computerClock) { // switch between program clock and computer clock

          try {
            Thread.currentThread().sleep(1000); // sleep every second
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          //					second++; //increase the timer by a second
          //					if (second == 60) //increase the minute and hour and day
          //					{
          //						second = 0;
          //						minute++;
          //					}
          //					if (minute ==60){
          //						minute = 0;
          //						hour++;
          //					}
          //					if (hour ==24){
          //						hour = 0;
          //						day++;
          //						weekday = (weekday+1) % weekdays.length;
          //						parent.UpdateCal(); //redraw the view
          //					}
          //					if ((day == 29) && (month == 2)){ //2 means February, check leap year
          //						if (year % 4 != 0 || (year % 100)== 0 && (year % 400) != 0){ // e.g. 1700 is not a
          // leap year
          //							day = 1;
          //							month++;
          //						}
          //
          //
          //					}
          //					if ((day == 30) && (month ==2)){ //handling of leap year
          //						day = 1;
          //						month++;
          //					}
          //					if (((month == 1) || (month == 3)|| (month == 5)|| (month == 7)|| (month == 8)
          // ||(month == 10) || (month == 12)) && (day== 32)){ //handling of months with 31 days
          //						day = 1;
          //						month++;
          //					}
          //					if (((month == 4) || (month == 6)|| (month == 9)|| (month == 11)) && (day== 31)){
          // //handling of months with 30 days
          //						day =1;
          //						month++;
          //					}
          //					if (month==13){ //switch to a new year
          //						month =1;
          //						year++;
          //					}
          currentTime.setTime(currentTime.getTime() + 1000);
          year = currentTime.getYear() + 1900;
          month = currentTime.getMonth() + 1;
          day = currentTime.getDate();
          hour = currentTime.getHours();
          minute = currentTime.getMinutes();
          second = currentTime.getSeconds();
          weekday = currentTime.getDay();

          // outputTheCurrentTime();
        }
        while (computerClock) {
          try { // obtain the computer time every second
            Thread.currentThread().sleep(1000);
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          Calendar cal = Calendar.getInstance();
          day = cal.get(Calendar.DATE);
          month = cal.get(Calendar.MONTH) + 1;
          year = cal.get(Calendar.YEAR);
          hour = cal.get(Calendar.HOUR_OF_DAY);
          minute = cal.get(Calendar.MINUTE);
          second = cal.get(Calendar.SECOND);
          weekday = cal.get(Calendar.DAY_OF_WEEK) - 1;
        }
      }
    } else { // Thread 2 is responsible for providing an user interface for accessing the timer
      int option = -1;
      while (option != 0) {
        System.out.println("1) Output the current time");
        // System.out.println("2) Modify the time");
        System.out.println("2) Switch mode (Program clock <-> Computer Clock)");
        System.out.println("0) Quit");

        System.out.print("Please choose an option: ");
        Scanner scanner = new Scanner(System.in);
        option = Integer.parseInt(scanner.next());
        if (option == 1) {
          outputTheCurrentTime();
        }

        //		    	if (option == 2){
        //		    		System.out.println("Please input the year, month(in integer), day, hour, minute
        // and second separated by a space: ");
        //		    		year = Integer.parseInt(scanner.next());
        //		    		month = Integer.parseInt(scanner.next());
        //		    		day = Integer.parseInt(scanner.next());
        //		    		hour = Integer.parseInt(scanner.next());
        //		    		minute = Integer.parseInt(scanner.next());
        //		    		second = Integer.parseInt(scanner.next());
        //
        //
        //		    		//Sun = 0, Mon = 1, Tue = 2, Wed = 3, Thurs = 4. Fri = 5, Sat = 6
        //		    		java.util.GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
        // //set the weekday of the input date
        //		    		cal.setTime(new Timestamp(year-1900, month-1, day, hour, minute, second, 0));
        //
        //		    		weekday = cal.get(java.util.Calendar.DAY_OF_WEEK)-1;
        //
        //
        //		    		if (parent != null)
        //		    			parent.UpdateCal(); //redraw the view
        //		    		System.out.println();
        //		    	}
        if (option == 3) { // switch between program timer and computer clock
          if (!computerClock) {
            computerClock = true;
            System.out.println("Computer Clock is in effective.");
          } else {
            computerClock = false;
            System.out.println("Program Clock is in effective.");
          }
          System.out.println();
        }
      }
    }
  }
コード例 #10
0
 private void populateTimestamp() {
   long seconds = getSeconds();
   int nanos = getNanos();
   timestamp.setTime(seconds * 1000);
   timestamp.setNanos(nanos);
 }
コード例 #11
0
  @Override
  /**
   * Method to evaluate scalar-column operation in vectorized fashion.
   *
   * @batch a package of rows with each column stored in a vector
   */
  public void evaluate(VectorizedRowBatch batch) {

    if (childExpressions != null) {
      super.evaluateChildren(batch);
    }

    // Input #2 is type date (epochDays).
    LongColumnVector inputColVector2 = (LongColumnVector) batch.cols[colNum];

    // Output is type HiveIntervalDayTime.
    IntervalDayTimeColumnVector outputColVector =
        (IntervalDayTimeColumnVector) batch.cols[outputColumn];

    int[] sel = batch.selected;
    boolean[] inputIsNull = inputColVector2.isNull;
    boolean[] outputIsNull = outputColVector.isNull;
    outputColVector.noNulls = inputColVector2.noNulls;
    outputColVector.isRepeating = inputColVector2.isRepeating;
    int n = batch.size;

    long[] vector2 = inputColVector2.vector;

    // return immediately if batch is empty
    if (n == 0) {
      return;
    }

    if (inputColVector2.isRepeating) {
      scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[0]));
      dtm.subtract(value, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
      outputColVector.setFromScratchIntervalDayTime(0);
      // Even if there are no nulls, we always copy over entry 0. Simplifies code.
      outputIsNull[0] = inputIsNull[0];
    } else if (inputColVector2.noNulls) {
      if (batch.selectedInUse) {
        for (int j = 0; j != n; j++) {
          int i = sel[j];
          scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
          dtm.subtract(value, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
          outputColVector.setFromScratchIntervalDayTime(i);
        }
      } else {
        for (int i = 0; i != n; i++) {
          scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
          dtm.subtract(value, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
          outputColVector.setFromScratchIntervalDayTime(i);
        }
      }
    } else {
        /* there are nulls */
      if (batch.selectedInUse) {
        for (int j = 0; j != n; j++) {
          int i = sel[j];
          scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
          dtm.subtract(value, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
          outputColVector.setFromScratchIntervalDayTime(i);
          outputIsNull[i] = inputIsNull[i];
        }
      } else {
        for (int i = 0; i != n; i++) {
          scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
          dtm.subtract(value, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
          outputColVector.setFromScratchIntervalDayTime(i);
        }
        System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
      }
    }

    NullUtil.setNullOutputEntriesColScalar(outputColVector, batch.selectedInUse, sel, n);
  }
コード例 #12
0
ファイル: Switch.java プロジェクト: openhsorg/openhs
  void setTimestamp() {
    Date date = new Date();

    timestamp.setTime(date.getTime());
  }
コード例 #13
0
 /**
  * 得到当前日期加入指定的second
  *
  * @return datetime 增加后的日期时间
  */
 public static Timestamp getCreaseTime(long second) {
   Timestamp nowDatetime = new Timestamp(System.currentTimeMillis());
   long time = (nowDatetime.getTime() / 1000) + second;
   nowDatetime.setTime(time * 1000);
   return nowDatetime;
 }