ycl

Artifact [cfabaeb91d]
Login

Artifact [cfabaeb91d]

Artifact cfabaeb91d49c00fe76ad1ec460c25fbd38c02be:


#! /usr/bin/env tclsh


namespace eval util {
	package require {ycl proc}
	[yclprefix] proc alias alias [yclprefix] proc alias
	alias aliases [yclprefix] proc aliases

	aliases {
		{ycl math}
		{ycl proc} {
			lambda
		}
	}

}

namespace path util

variable doc::count {
	description {
		counts the number of things in a time 
	}
	args {
		time {
			seconds since the epoch
		}
		report {
			description {
				a list of things to report

					years months days hours minutes seconds weeks weekdays

				each item is calculated using the time remaining from the
				calculation of the previous item

					this makes it possible to get 

						for example

							years months days hours minutes seconds

							with one call
			}
		}
	}
}
proc count {time report} {
	set res {}
	set units {
		seconds minutes hours days weekdays weeks months or years
	}
	foreach unit $report {
		if {$unit ni $units} {
			error [list bad unit $unit]
		}
		lassign [math count $time [lambda {time unit number} {
			clock add 0 $number $unit
		} $time $unit]] value used
		lappend res $value
		set time [expr {$time - $used}]
	}
	return $res
}

proc seconds time {
	set time [clock scan $time -timezone :UTC -format {%Y %m %d %H %M %S}]
	return $time
}