Esempio n. 1
1
  /** Initializes contained components. */
  private void initComponents() {
    final SimpleDateFormat format = new SimpleDateFormat("mm:ss");
    final Calendar c = Calendar.getInstance();
    final JLabel counter = new JLabel();

    counter.setForeground(Color.red);
    counter.setFont(counter.getFont().deriveFont((float) (counter.getFont().getSize() + 5)));

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    GridBagConstraints constraints = new GridBagConstraints();

    JLabel messageLabel =
        new JLabel(
            GuiActivator.getResources().getI18NString("service.gui.security.SECURITY_ALERT"));

    messageLabel.setForeground(Color.WHITE);

    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 0;
    add(messageLabel, constraints);

    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 1;
    add(counter, constraints);

    ZrtpControl zrtpControl = null;
    if (securityControl instanceof ZrtpControl) zrtpControl = (ZrtpControl) securityControl;

    long initialSeconds = 0;

    if (zrtpControl != null) initialSeconds = zrtpControl.getTimeoutValue();

    c.setTimeInMillis(initialSeconds);

    counter.setText(format.format(c.getTime()));

    if (initialSeconds > 0)
      timer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              if (c.getTimeInMillis() - 1000 > 0) {
                c.add(Calendar.SECOND, -1);
                counter.setText(format.format(c.getTime()));
              }
            }
          },
          1000,
          1000);
  }
Esempio n. 2
0
  /**
   * For the contracts whose volume shifts from the front contract to the back contract on the day
   * preceding the 2nd Friday of expiration month of the front contract.
   */
  public static String getMostLiquid(Calendar asOfDate) {

    int monthNow = asOfDate.get(Calendar.MONTH);
    int yearNow = asOfDate.get(Calendar.YEAR);
    int mostLiquidYear = yearNow;

    int mostLiquidMonth = frontMonths.get(monthNow);

    // special case with December
    if (monthNow == Calendar.DECEMBER) {
      mostLiquidYear = yearNow + 1;
    }

    if (keepCurrent(asOfDate)) {
      mostLiquidMonth = monthNow;
      mostLiquidYear = yearNow;
    }

    Calendar mostLiquidDate = Calendar.getInstance();
    mostLiquidDate.set(Calendar.DAY_OF_MONTH, 1);
    mostLiquidDate.set(Calendar.MONTH, mostLiquidMonth);
    mostLiquidDate.set(Calendar.YEAR, mostLiquidYear);

    SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
    return df.format(mostLiquidDate.getTime());
  }
 public void setSelectedItem(Object anItem) {
   if (anItem == null) {
     return;
   }
   if (anItem instanceof Date) {
     try {
       selectedDate = this.dateFormat.format((Date) anItem);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   } else {
     try {
       String strDate = anItem.toString().trim();
       if (strDate.length() != 10 && strDate.length() != 19) {
         return;
       }
       String pattern = dateFormat.toPattern();
       if (strDate.length() == 10 && pattern.length() == 19) {
         strDate = strDate + selectedDate.substring(10);
       }
       dateFormat.parse(strDate);
       selectedDate = strDate;
     } catch (Exception ex) {
       throw new UnsupportedOperationException(
           "Invalid datetime: string ["
               + anItem
               + "], format is ["
               + dateFormat.toPattern()
               + "]. ");
     }
   }
   fireContentsChanged(this, -1, -1);
 }
  public Object objectDone() {
    Object o = super.objectDone();
    BSONObject b = (BSONObject) o;

    if (!_lastArray) {
      if (b.containsField("$oid")) {
        o = new ObjectId((String) b.get("$oid"));
        if (!isStackEmpty()) {
          gotObjectId(_lastName, (ObjectId) o);
        } else {
          setRoot(o);
        }
      } else if (b.containsField("$date")) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
        o = format.parse((String) b.get("$date"), new ParsePosition(0));
        if (!isStackEmpty()) {
          cur().put(_lastName, o);
        } else {
          setRoot(o);
        }
      } else if (b.containsField("$regex")) {
        o = Pattern.compile((String) b.get("$regex"), BSON.regexFlags((String) b.get("$options")));
        if (!isStackEmpty()) {
          cur().put(_lastName, o);
        } else {
          setRoot(o);
        }
      }
    }

    return o;
  }
 /** Returns the date the message was sent (or received if the sent date is null. */
 public String getDate() throws MessagingException {
   Date date;
   SimpleDateFormat df = new SimpleDateFormat("EE M/d/yy");
   if ((date = message.getSentDate()) != null) return (df.format(date));
   else if ((date = message.getReceivedDate()) != null) return (df.format(date));
   else return "";
 }
Esempio n. 6
0
 public String getPageContents() {
   StringBuffer buffer = new StringBuffer();
   SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
   buffer
       .append("== {{int:filedesc}} ==\n")
       .append("{{Information\n")
       .append("|description=")
       .append(description)
       .append("\n")
       .append("|source=")
       .append("{{own}}\n")
       .append("|author=[[User:"******"]]\n");
   if (dateCreated != null) {
     buffer
         .append("|date={{According to EXIF data|")
         .append(isoFormat.format(dateCreated))
         .append("}}\n");
   }
   buffer
       .append("}}")
       .append("\n")
       .append("== {{int:license-header}} ==\n")
       .append("{{self|cc-by-sa-3.0}}\n\n")
       .append("{{Uploaded from Mobile|platform=Android|version=")
       .append(CommonsApplication.APPLICATION_VERSION)
       .append("}}\n")
       .append("{{subst:unc}}"); // Remove when we have categorization
   return buffer.toString();
 }
  /** base constructer from a java.util.date object */
  public DERGeneralizedTime(Date time) {
    SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");

    dateF.setTimeZone(new SimpleTimeZone(0, "Z"));

    this.time = dateF.format(time);
  }
Esempio n. 8
0
  /**
   * 현재날짜(System TimeZone 및 Locale 기준)에서 몇일 전,후의 날짜를 구한다.
   *
   * @param day 변경할 일수
   * @return 현재날짜에서 입력한 일수를 계산한 날짜(yyyyMMdd)
   */
  public static String getDateWithSpan(long day) {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");

    java.util.Date date = new java.util.Date();
    java.util.Date spanDate = new java.util.Date(date.getTime() + (day * 1000 * 60 * 60 * 24));

    return fmt.format(spanDate);
  }
Esempio n. 9
0
 public static String getDateFormat(long lDate, String format) {
   String result = null;
   if (format != null) {
     SimpleDateFormat sdf = new SimpleDateFormat(format);
     result = sdf.format(lDate);
   }
   return result;
 }
Esempio n. 10
0
 /**
  * Convert a string to date.
  *
  * @param s Given date string
  * @return Date object
  */
 public static Date toDate(String s) {
   SimpleDateFormat df = new SimpleDateFormat(DateUtils.DATE_FORMAT);
   try {
     return df.parse(s);
   } catch (ParseException e) {
     return null;
   }
 }
Esempio n. 11
0
  // 현재날짜
  public static String getCurrentDate() {
    Calendar now = Calendar.getInstance();
    long lCurDate = now.getTimeInMillis();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    String sCurrentDate = sdf.format(lCurDate);

    return sCurrentDate;
  }
  /**
   * Returns the directory where the recording should be stored
   *
   * @return the directory of the new recording
   */
  String getRecordingDirectory() {
    if (this.recordingDirectory == null) {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd.HH-mm-ss.");
      this.recordingDirectory =
          dateFormat.format(new Date()) + getID() + ((name != null) ? "_" + name : "");
    }

    return this.recordingDirectory;
  }
Esempio n. 13
0
  /**
   * 현재날짜를 dateType형식으로 보여준다. ForExample : yyyy yyyy-MM yyyy-MM-dd yyyyMMdd
   *
   * @param dateType
   * @return
   */
  public static String getCurrentDateByType(String dateType) {
    Calendar now = Calendar.getInstance();
    long lCurDate = now.getTimeInMillis();

    SimpleDateFormat sdf = new SimpleDateFormat(dateType);
    String sCurrentDate = sdf.format(lCurDate);

    return sCurrentDate;
  }
Esempio n. 14
0
  static void printResult(Calendar from, Calendar to) {
    Date fromDate = from.getTime();
    Date toDate = to.getTime();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    System.out.print(sdf.format(fromDate) + " ~ " + sdf.format(toDate) + ":");
    System.out.println(paycheckCount(from, to));
  }
Esempio n. 15
0
  /**
   * Convert a date to required String format.
   *
   * @param date Given date.
   * @param format Given String ("dd-MM-yyyy" for 01-01-2000 format "dd-MMM-YYYY" for 01-Jan-2000
   *     format)
   * @return Date in required format.
   */
  public static String formatDateString(java.util.Date date, String format) {
    if ((date == null) || (format == null)) {
      return null;
    }

    // Set the date
    SimpleDateFormat fm = new SimpleDateFormat(format);
    return fm.format(date);
  }
Esempio n. 16
0
  public List<MersVO> mersData() {
    List<MersVO> list = new ArrayList<MersVO>();
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
    StringTokenizer st = new StringTokenizer(sdf.format(date), "-");
    int year = Integer.parseInt(st.nextToken());
    int month = Integer.parseInt(st.nextToken());
    int day = Integer.parseInt(st.nextToken());
    try {
      Document doc = Jsoup.connect("http://www.cdc.go.kr/CDC/cms/content/15/63315_view.html").get();
      // System.out.println(doc);
      Elements trs = doc.select("table tbody tr");
      // System.out.println(trs);
      String data = "";
      String[] temp = {"panel panel-primary", "panel panel-green", "panel panel-yellow"};
      int i = 0;
      for (Element tr : trs) {
        Iterator<Element> it = tr.getElementsByTag("td").iterator();

        // if(i==2) break;
        while (it.hasNext()) {

          MersVO vo = new MersVO();
          vo.setType(it.next().text());
          vo.setMers(it.next().text().replace("*", ""));
          /*vo.setYsum(it.next().text().replace(",", ""));
          vo.setPlus(it.next().text());
          vo.setMinus(it.next().text());*/

          if (data.equals("")) {
            data = it.next().text();
            vo.setIng(data);
          } else {
            vo.setIng(data);
          }
          vo.setNsum(it.next().text().replace(",", ""));
          vo.setHouse(it.next().text());
          vo.setOffice(it.next().text());
          vo.setDis(it.next().text().replace(",", ""));
          vo.setDiv1(temp[i]);
          vo.setYear(year);
          vo.setMonth(month);
          if (i == 2) {
            vo.setDay(day - 1);
          } else {
            vo.setDay(day);
          }
          list.add(vo);
          i++;
        }
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
    return list;
  }
Esempio n. 17
0
  public static String getShowString(String current, String then) {
    try {
      Date c = formatter.parse(current);
      Date t = formatter.parse(then);
      MDebug.log("|" + (c.getTime() - t.getTime()) + "|");
    } catch (Exception ex) {

    }
    return "right";
  }
  private void saveData(TelemetryData data) {
    PrintWriter out;
    boolean newFile = false;

    if (saveCnt > 25000) {
      File logFile;
      int i;

      logFile = new File(telemetryDir + 99 + ".log");
      logFile.delete();
      newFile = true;

      for (i = 99; i > 0; i--) {
        logFile = new File(telemetryDir + (i - 1) + ".log");
        logFile.renameTo(new File(telemetryDir + i + ".log"));
      }
      saveCnt = 0;
    }

    try {
      String text = "";
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);

      saveCnt++;
      out = new PrintWriter(new FileOutputStream(telemetryDir + "0.log", true));
      if (newFile) {
        text =
            "Time\tLatitude\tLongitude\tSpeed\tAcceleration X\tAcceleration Y\tAcceleration Z\tCoG\tOrientation Y\tOrientation Z\n\n";
        out.print(text);
      }
      text = dateFormat.format(new Date(System.currentTimeMillis())) + "\t";
      if (posValid) text = text + lastLat + "\t" + lastLon + "\t" + m_lastSpeed + "\t";
      else text = text + "-\t-\t-\t";
      text =
          text
              + data.getAccelX()
              + "\t"
              + data.getAccelY()
              + "\t"
              + data.getAccelZ()
              + "\t"
              + data.CoG
              + "\t"
              + data.getOrientY()
              + "\t"
              + data.getOrientZ()
              + "\n\n";
      out.print(text);
      out.close();
    } catch (IOException ioe) {
    }
  }
Esempio n. 19
0
  public static void main(String[] av) {
    /** Today's date */
    Calendar now = Calendar.getInstance();

    /* Do "DateFormat" using "simple" format. */
    SimpleDateFormat formatter = new SimpleDateFormat("E yyyy/MM/dd 'at' hh:mm:ss a zzz");
    System.out.println("It is now " + formatter.format(now.getTime()));

    // Add a "# of years" increment to the existing Calendar object
    now.add(Calendar.YEAR, -2);

    System.out.println("Two years ago was " + formatter.format(now.getTime()));
  }
Esempio n. 20
0
 public static boolean isValidDate(String dob) {
   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
   Date testDate = null;
   try {
     testDate = sdf.parse(dob);
   } catch (ParseException e) {
     return false;
   }
   if (!sdf.format(testDate).equals(dob)) {
     return false;
   }
   return true;
 }
  // converts the XML date format to the SQL TIMESTAMP format
  // "Dec-03-01 18:38:23" => "0000-00-00 00:00:00"
  static String convertToSQLTime(String xmlTime) {
    SimpleDateFormat xmlFormat = new SimpleDateFormat("MMM-dd-yy HH:mm:ss");
    SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date inputDate = null;
    try {
      inputDate = xmlFormat.parse(xmlTime);
    } catch (ParseException pe) {
      System.out.println("ERROR: could not parse \"" + xmlTime + "\"");
      System.exit(3);
    }

    return sqlFormat.format(inputDate);
  }
 private void setTimeZone(String line) throws JBookTraderException {
   String timeZone = line.substring(line.indexOf('=') + 1);
   TimeZone tz = TimeZone.getTimeZone(timeZone);
   if (!tz.getID().equals(timeZone)) {
     String msg =
         "The specified time zone " + "\"" + timeZone + "\"" + " does not exist." + LINE_SEP;
     msg += "Examples of valid time zones: " + " America/New_York, Europe/London, Asia/Singapore.";
     throw new JBookTraderException(msg);
   }
   sdf = new SimpleDateFormat("MMddyyHHmmss");
   // Enforce strict interpretation of date and time formats
   sdf.setLenient(false);
   sdf.setTimeZone(tz);
 }
  void test2() {
    Locale defaultLocale = Locale.getDefault();
    TimeZone reservedTimeZone = TimeZone.getDefault();
    Date d = new Date(2005 - 1900, Calendar.DECEMBER, 22);
    String formatted;

    TimeZone tz;
    SimpleDateFormat df;

    try {
      for (int i = 0; i < TIMEZONES.length; i++) {
        tz = TimeZone.getTimeZone(TIMEZONES[i]);
        TimeZone.setDefault(tz);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(OSAKA));
        Locale.setDefault(defaultLocale);
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_OSAKA[i])) {
          throw new RuntimeException(
              "TimeZone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_OSAKA[i]);
        }

        df.parse(DISPLAY_NAMES_OSAKA[i]);

        Locale.setDefault(KYOTO);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
          throw new RuntimeException(
              "Timezone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_KYOTO[i]);
        }
        df.parse(DISPLAY_NAMES_KYOTO[i]);
      }
    } catch (ParseException pe) {
      throw new RuntimeException("parse error occured" + pe);
    } finally {
      // restore the reserved locale and time zone
      Locale.setDefault(defaultLocale);
      TimeZone.setDefault(reservedTimeZone);
    }
  }
  public static void main(String[] args) throws ParseException {
    // String dir =
    // "C:/Users/Joschka/Documents/shared-svn/projects/sustainability-w-michal-and-dlr/data/";
    String dir = "d:/svn-vsp/sustainability-w-michal-and-dlr/data/";

    //        String taxisOverTimeFile = dir +
    // "taxi_berlin/2014_10_bahnstreik/VEH_IDs_2014-10/oct/oct_taxis.txt";
    //        String taxisOverTimeFile = dir + "taxi_berlin/2013/status/taxisovertime.csv";
    String taxisOverTimeFile = dir + "taxi_berlin/2013/vehicles/taxisweekly.csv";

    // String networkFile = dir + "scenarios/2015_02_basic_scenario_v6/berlin_brb.xml";
    String networkFile = dir + "network/berlin.xml"; // only Berlin!!!

    String zoneShpFile = dir + "shp_merged/zones.shp";
    String zoneXmlFile = dir + "shp_merged/zones.xml";

    // String vehicleFile = dir + "scenarios/2015_02_basic_scenario_v6/taxis4to4_EV";
    String vehicleFile = dir + "scenarios/2015_08_only_berlin_v1/taxis4to4_EV";

    String statusMatrixFile = dir + "taxi_berlin/2013/status/statusMatrixAvg.xml";

    BerlinTaxiVehicleCreatorV3 btv = new BerlinTaxiVehicleCreatorV3();
    btv.evShare = 0.0;
    btv.minTime = 4.0 * 3600;
    btv.maxTime = 17.0 * 3600;
    btv.readTaxisOverTime(taxisOverTimeFile);
    //        btv.createAverages(SDF.parse("2014-10-15 03:30:00"));
    btv.createAverages(SDF.parse("2013-04-16 03:30:00"));
    btv.prepareNetwork(networkFile, zoneShpFile, zoneXmlFile);
    btv.prepareMatrices(statusMatrixFile);
    btv.createVehicles();

    btv.writeVehicles(vehicleFile);
  }
Esempio n. 25
0
 /**
  * Start recording
  *
  * @param stub
  */
 public static void startRecorder(String stub) {
   try {
     stamp = new SimpleDateFormat("HH:mm:ss");
     SimpleDateFormat dateformat = new SimpleDateFormat("yyMMdd");
     Date d = new Date();
     String s = dateformat.format(d);
     String name = logdir + stub + s + ".txt";
     R = new RandomAccessFile(name, "rw");
     System.out.println("Log file: " + name);
     long N = R.length();
     R.seek(N);
     recording = true;
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 26
0
 public static String getDateTaken(File file) {
   Directory exifDirectory = getMetaDirectory(file);
   try {
     SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss"); // original format
     if (exifDirectory != null) {
       String dateStr = exifDirectory.getString(ExifDirectory.TAG_DATETIME_ORIGINAL);
       Date date = formatter.parse(dateStr);
       formatter = new SimpleDateFormat("MM/dd/yyyy"); // desired format
       return formatter.format(date);
     }
     return "no date picture taken info";
   } catch (ParseException e) {
     e.printStackTrace();
   }
   return "error occurred while getting the date";
 }
  protected void load() throws IOException {

    BufferedReader is = new BufferedReader(new FileReader("ReminderService.txt"));
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy MM dd hh mm");
    String aLine;
    while ((aLine = is.readLine()) != null) {
      ParsePosition pp = new ParsePosition(0);
      Date date = formatter.parse(aLine, pp);
      if (date == null) {
        message("Invalid date in " + aLine);
        continue;
      }
      String mesg = aLine.substring(pp.getIndex());
      l.add(new Item(date, mesg));
    }
  }
Esempio n. 28
0
  public BackTestFileWriter(Strategy strategy) throws JArbitragerException {
    decimalFormat = NumberFormatterFactory.getNumberFormatter(5);
    dateFormat = new SimpleDateFormat("MMddyy,HHmmss");
    dateFormat.setTimeZone(strategy.getTradingSchedule().getTimeZone());

    File marketDataDir = new File(MARKET_DATA_DIR);
    if (!marketDataDir.exists()) {
      marketDataDir.mkdir();
    }

    String fullFileName = MARKET_DATA_DIR + FILE_SEP + strategy.getName() + ".txt";
    try {
      boolean fileExisted = new File(fullFileName).exists();
      writer = new PrintWriter(new BufferedWriter(new FileWriter(fullFileName, true)));
      if (!fileExisted) {
        StringBuilder header =
            getHeader(
                strategy.getInstrument1().getContract().m_symbol,
                strategy.getInstrument2().getContract().m_symbol);
        writer.println(header);
      }
    } catch (IOException ioe) {
      throw new JArbitragerException("Could not write to file " + strategy.getName());
    }
  }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String time = in.next();

    // Set format for input and output
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ssa");
    SimpleDateFormat out = new SimpleDateFormat("HH:mm:ss");

    try {
      Date inTime = sdf.parse(time);
      System.out.println(out.format(inTime));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 30
0
 /**
  * Generates a file name for the call based on the current date and the names of the peers in the
  * call.
  *
  * @param ext file extension
  * @return the file name for the call
  */
 private String generateCallFilename(String ext) {
   String filename = FORMAT.format(new Date()) + "-call";
   int maxLength = MAX_FILENAME_LENGTH - 2 - filename.length() - ext.length();
   String peerName = getCallPeerName(maxLength);
   filename += ((!peerName.equals("")) ? "-" : "") + peerName + "." + ext;
   return filename;
 }