コード例 #1
0
ファイル: CommandUptime.java プロジェクト: Riaku/FoxBot
  @Override
  public void execute(final MessageEvent event, final String[] args) {
    User sender = event.getUser();
    Channel channel = event.getChannel();

    if (!System.getProperty("os.name").toLowerCase().contains("win")) {
      try {
        int unixTime =
            Integer.parseInt(
                new Scanner(new FileInputStream("/proc/uptime"))
                    .next()
                    .replaceAll("\\.[0-9]+", ""));
        int day = (int) TimeUnit.SECONDS.toDays(unixTime);
        long hours = TimeUnit.SECONDS.toHours(unixTime) - (day * 24);
        long minute =
            TimeUnit.SECONDS.toMinutes(unixTime) - (TimeUnit.SECONDS.toHours(unixTime) * 60);
        long seconds =
            TimeUnit.SECONDS.toSeconds(unixTime) - (TimeUnit.SECONDS.toMinutes(unixTime) * 60);

        channel
            .send()
            .message(
                Utils.colourise(
                    String.format(
                        "&2System uptime: &r%s days %s hours %s minutes %s seconds",
                        day, hours, minute, seconds)));
      } catch (FileNotFoundException ex) {
        sender.send().notice("File \"/proc/uptime\" not found. Are you sure you're using Linux?");
      }
      return;
    }
    sender.send().notice("This command is only supported on Unix based systems.");
  }
コード例 #2
0
  private String calculateRemTime(long seconds) {
    int days = (int) TimeUnit.SECONDS.toDays(seconds);

    long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(days);

    long minutes =
        TimeUnit.SECONDS.toMinutes(seconds)
            - TimeUnit.DAYS.toMinutes(days)
            - TimeUnit.HOURS.toMinutes(hours);

    long secs =
        TimeUnit.SECONDS.toSeconds(seconds)
            - TimeUnit.DAYS.toSeconds(days)
            - TimeUnit.HOURS.toSeconds(hours)
            - TimeUnit.MINUTES.toSeconds(minutes);

    return String.format("%dd %d:%02d:%02d", days, hours, minutes, secs);
  }
コード例 #3
0
ファイル: SystemManager.java プロジェクト: narry/odenos
 /*
  * Method for monitoring the active components having timer. If
  * ActiveComponent is dead, it insert error state into the property.
  */
 @SuppressWarnings("unused")
 private void monitorAliveOfComponents(long period) {
   TimerTask task = new CheckComponentsTask(this.getProperty().getBaseUri());
   Timer timer = new Timer();
   timer.schedule(task, TimeUnit.SECONDS.toSeconds(AliveIntervalTime), period);
 }
コード例 #4
0
ファイル: live_first.java プロジェクト: 29jitender/Mixpanel
  @Override
  public void methodToCallback(String print) {
    String timediff;

    live_list = new ArrayList<HashMap<String, String>>();

    try {
      array1 = new JSONArray(print);
      for (int i = 0; i < array1.length(); i++) {
        JSONObject obj1 = array1.getJSONObject(i);
        HashMap<String, String> map = new HashMap<String, String>();

        String event = obj1.getString("event");
        map.put("name", event);
        map.put("fulldata", obj1.toString());
        /// caluclation difference in time
        String time = obj1.getString("$ts"); // time in seconds	
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.set(Calendar.SECOND, 0);
        long timenow = cal.getTimeInMillis();

        try {
          long recivetime = (long) Double.parseDouble(time);

          long diff = (timenow - recivetime) / 1000;
          int day = (int) TimeUnit.SECONDS.toDays(diff);
          long hours = TimeUnit.SECONDS.toHours(diff) - (day * 24);
          long minute = TimeUnit.SECONDS.toMinutes(diff) - (TimeUnit.SECONDS.toHours(diff) * 60);
          long second = TimeUnit.SECONDS.toSeconds(diff) - (TimeUnit.SECONDS.toMinutes(diff) * 60);

          if (day == 0) {
            if (hours == 0) {
              if (minute == 0) {
                timediff = second + " S ago";

              } else {
                timediff = minute + " M ago";
              }

            } else {
              timediff = hours + " H ago";
            }

          } else {
            timediff = day + " D ago";
          }

          map.put("time", timediff);

        } catch (NumberFormatException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        ////
        ///////// adding region/////////

        ///////////////////
        String location;
        JSONObject obj2 = null;
        try {
          obj2 = obj1.getJSONObject("properties");

          String region = obj2.getString("$region");
          String country = obj2.getString("mp_country_code");
          location = region + "," + country;
        } catch (Exception e) {
          if (obj2.has("mp_country_code")) {
            location = obj2.getString("mp_country_code");
          } else {
            location = "N/A";
          }

          e.printStackTrace();
        }
        map.put("location", location);
        /////////////////////

        live_list.add(map);
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    /////////// updateing data into list
    ListAdapter temp = null;
    setListAdapter(temp);
    Collections.reverse(live_list); // reversing the order of list
    adapter =
        new SimpleAdapter(
            this,
            live_list,
            R.layout.list_live_first,
            new String[] {"name", "time", "location", "fulldata"},
            new int[] {R.id.live_name, R.id.live_time, R.id.live_location});
    setadapter();
  }