/*
 * Operations.java
 *
 * Created on 30. prosinec 2005, 7:35
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package cz.pcland.gavisualization;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import javax.swing.border.*;

/**
 *
 * @author petr
 */
public class Operations {
    public static String toHex(int i){
        String s = Integer.toHexString(i);
        if(s.length() == 1) {
            s = "0"+s;
        }
        
        return s;
    }
    
    
    public static String getColoredText(Color cl, String s) {
        String txt = "<font color=#" +
                toHex(cl.getRed()) +
                toHex(cl.getGreen()) +
                toHex(cl.getBlue())
                + ">" + s + "</font>";
        
        return txt;
    }
    
    
    public static String getTime(long millSec){
        long sec = 0;
        long min = 0;
        long hours = 0;
        long months = 0;
        long days = 0;
        long years = 0;
        long rest = 0;
        
        sec = millSec/1000;
        //System.out.println("sec1: " + sec);
        if(sec >= 60) {
            
            min = sec/60;
            sec = sec%60;
           // System.out.println("min1: " + min);
           // System.out.println("sec2: " + sec);
            
            if(min >=60) {
                hours = min/60;
               // System.out.println("hod1: " + hours);
                min = min%60;
              //  System.out.println("min2: " + min);
                
                if(hours>=24){
                    days = hours/24;
              //      System.out.println("hod2: " + hours);
                    hours = hours%24;
                    
                    if(days>=365) {
                        years = days/365;
                        days = days%365;
                    }
                }
            }
            
            
        }
        
        if(years != 0) return String.valueOf(years) + " years";
        if(months != 0) return String.valueOf(months) + " months";
        if(days != 0) return String.valueOf(days) + " days";
        if(hours != 0) return String.valueOf(hours) + " hours";
        return String.valueOf(min) + " min " + String.valueOf(sec) +" sec";
    }
    
    /** Creates a new instance of Operations */
    public Operations() {
    }
    
}
