Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (0fb94eb33a6494f36b68c63b8d1418369a78af87)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Jaka Kranjc <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (0fb94eb33a6494f36b68c63b8d1418369a78af87)
  • Date: Sat, 5 Jul 2008 08:18:04 -0500

GIT changes to master sorcery by Jaka Kranjc <lynxlynxlynx AT sourcemage.org>:

ChangeLog | 4 ++
usr/sbin/gaze | 15 +---------
var/lib/sorcery/modules/libtime | 58
++++++++++++++++++++--------------------
3 files changed, 35 insertions(+), 42 deletions(-)

New commits:
commit 0fb94eb33a6494f36b68c63b8d1418369a78af87
Author: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>

libtime: removed the now unused fix_zero_time and epoch_to_hm functions

commit 0577c86361421e551247f3f240cb1577f29f6c87
Author: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>

libtime:
made use of pretty_print_time in other parts of the code

commit bf1be2b1cfdade424587ed1d64dd112811e21309
Author: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
Commit: Jaka Kranjc <lynxlynxlynx AT sourcemage.org>

libtime, gaze: factored out a pretty_print_time function and improved it
to not show 0 parts and incorporated the fix_zero_time in it

diff --git a/ChangeLog b/ChangeLog
index 85a9627..05f1c9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@
stage_install_ordinary
fixed a regression that caused us not to install excluded configs
#14339
* libstate: removed three unused variable definitions
+ * libtime, gaze: factored out a pretty_print_time function and
improved it
+ to not show 0 parts and incorporated the fix_zero_time in it
+ made use of pretty_print_time in other parts of the code
+ * libtime: removed the now unused fix_zero_time and epoch_to_hm
functions

2008-07-04 Jaka Kranjc <lynxlynxlynx AT sourcemage.org>
* libmisc: removed older, commented-out versions of
config_[gs]et_option
diff --git a/usr/sbin/gaze b/usr/sbin/gaze
index 7bce60e..fd65095 100755
--- a/usr/sbin/gaze
+++ b/usr/sbin/gaze
@@ -2078,8 +2078,7 @@ function gaze_time() {

if [[ $GAZE_VERBOSE != 0 ]]; then
message -n "Casting ${SPELL_COLOR}$spell$DEFAULT_COLOR took "
- time=$(epoch_to_hm $diff)
- fix_zero_time "$time"
+ pretty_print_time $diff
else
echo "$spell:$diff"
fi
@@ -2088,17 +2087,7 @@ function gaze_time() {
if [[ -n $2 ]]; then
message -n "${MESSAGE_COLOR}Total time:$DEFAULT_COLOR "
if [[ $GAZE_VERBOSE != 0 ]]; then
- # date can only print day of year starting with 1, so we can't use it,
- # yet we have to display the number of days, since the total can be big
- awk -v sum=$sum 'END {
- days = int(sum/3600/24)
- sum -= days * 3600 * 24
- hours = int(sum/3600)
- sum -= hours * 3600
- minutes = int(sum/60)
-
- print days "d " hours "h " minutes "m "
- }' /dev/null
+ pretty_print_time $sum
else
echo $sum
fi
diff --git a/var/lib/sorcery/modules/libtime b/var/lib/sorcery/modules/libtime
index 0797888..2ccc35e 100755
--- a/var/lib/sorcery/modules/libtime
+++ b/var/lib/sorcery/modules/libtime
@@ -103,19 +103,19 @@ function compute_all_cast_times() {
else
message -n "Last cast time of ${SPELL_COLOR}$spell$DEFAULT_COLOR: "
time=$(echo "$times" | tail -n 1)
- fix_zero_time "$(epoch_to_hm $time)"
+ pretty_print_time $time

message -n "Median cast time of ${SPELL_COLOR}$spell$DEFAULT_COLOR: "
time=$(echo "$times" | compute_median)
- fix_zero_time "$(epoch_to_hm $time)"
+ pretty_print_time $time

message -n "Mean cast time of ${SPELL_COLOR}$spell$DEFAULT_COLOR: "
time=$(echo "$times" | compute_mean)
- fix_zero_time "$(epoch_to_hm $time)"
+ pretty_print_time $time

message -n "Weighted mean cast time of
${SPELL_COLOR}$spell$DEFAULT_COLOR: "
time=$(echo "$times" | compute_weighted_mean last-cast
$(private_installed_version $spell))
- fix_zero_time "$(epoch_to_hm $time)"
+ pretty_print_time $time
echo
fi

@@ -195,34 +195,34 @@ function compute_median() {

#---------------------------------------------------------------------
##
-## Converts a time in seconds since the epoch to HH MM
+## Converts a time in seconds into a human readable format
##
-## @param seconds
-## @param padding - if set will pad times with 0
-## @Stdout time
+## @param time in seconds
+## @Stdout time (DD:HH:MM or HH:MM or MM or "less than a minute")
#---------------------------------------------------------------------
-function epoch_to_hm() {
- if [[ -z $2 ]]; then
- date -u -d "1970-01-01 $1 seconds" "+%-Hh %-Mm"
- else
- date -u -d "1970-01-01 $1 seconds" "+%Hh %Mm"
- fi
-}
+function pretty_print_time() {
+ # date can only print day of year starting with 1, so we can't use it,
+ # yet we have to display the number of days, since the total can be big
+ awk -v sum=$1 'END {
+ days = int(sum/3600/24)
+ sum -= days * 3600 * 24
+ hours = int(sum/3600)
+ sum -= hours * 3600
+ minutes = int(sum/60)
+ # sum is now < 3600

-#---------------------------------------------------------------------
-##
-## Converts a time of "0h 0m" to an english string
-##
-## @param time
-## @Stdout possibly fixed time
-#---------------------------------------------------------------------
-function fix_zero_time() {
- local time=$1
- if [[ $time == "0h 0m" ]]; then
- echo "less than a minute."
- else
- echo $time
- fi
+ if (sum < 60 && days == 0 && hours == 0) {
+ print "less than a minute."
+ exit
+ }
+ if (days > 0) {
+ print days "d " hours "h " minutes "m "
+ } else if (hours > 0) {
+ print hours "h " minutes "m "
+ } else {
+ print minutes "m "
+ }
+ }' /dev/null
}

#---------------------------------------------------------------------



  • [SM-Commit] GIT changes to master sorcery by Jaka Kranjc (0fb94eb33a6494f36b68c63b8d1418369a78af87), Jaka Kranjc, 07/05/2008

Archive powered by MHonArc 2.6.24.

Top of Page