From ef1ea08532c7128f327561f08ec642414f0a72e0 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 18 Aug 2010 01:18:55 +0200 Subject: [PATCH] Add age functions. --- src/fr/devinsy/util/SimpleChronometer.java | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) mode change 100755 => 100644 src/fr/devinsy/util/SimpleChronometer.java diff --git a/src/fr/devinsy/util/SimpleChronometer.java b/src/fr/devinsy/util/SimpleChronometer.java old mode 100755 new mode 100644 index c172db6..4da6eba --- a/src/fr/devinsy/util/SimpleChronometer.java +++ b/src/fr/devinsy/util/SimpleChronometer.java @@ -47,4 +47,103 @@ public class SimpleChronometer // return(result); } + + + /** + * + */ + static public String shortHumanString(long interval) + { + String result; + + if (interval < 1000) + { + result = interval + " ms"; + } + else if (interval < 60*1000) + { + result = interval/1000 + " s"; + } + else if (interval < 60*60*1000L) + { + result = interval/(60*1000L) + " mn"; + } + else if (interval < 2*60*60*1000L) + { + result = interval/(60*1000L) + " heure"; + } + else if (interval < 24*60*60*1000L) + { + result = interval/(60*60*1000L) + " heures"; + } + else if (interval < 2*24*60*60*1000L) + { + result = interval/(24*60*60*1000L) + " jour"; + } + else if (interval < 7*24*60*60*1000L) + { + result = interval/(24*60*60*1000L) + " jours"; + } + else if (interval < 2*7*24*60*60*1000L) + { + result = interval/(7*24*60*60*1000L) + " semaine"; + } + else if (interval < 30*24*60*60*1000L) + { + result = interval/(7*24*60*60*1000L) + " semaines"; + } + else if (interval < 52*7*24*60*60*1000L) + { + result = interval/(30*24*60*60*1000L) + " mois"; + } + else if (interval < 2*52*7*24*60*60*1000L) + { + result = interval/(52*7*24*60*60*1000L) + " année"; + } + else + { + result = interval/(52*7*24*60*60*1000L) + " années"; + } + + + // + return(result); + } + + + /** + * TO BE COMPLETED. + */ + static public String humanString(long interval) + { + String result; + + if (interval < 1000) + { + result = interval + "ms"; + } + else if (interval < 60*1000) + { + result = interval/1000 + "," + interval%1000 + "s"; + } + else if (interval < 60*60*1000) + { + result = interval/1000 + "," + interval%1000 + "s"; + } + else if (interval < 24*60*60*1000) + { + result = interval/1000 + "," + interval%1000 + "s"; + } + else if (interval < 7*24*60*60*1000) + { + result = interval/1000 + "," + interval%1000 + "s"; + } + else // if (interval < 7*24*60*60*1000) + { + result = interval/1000 + "," + interval%1000 + "s"; + } + + // + return(result); + } }