Posted to tcl by dbohdan at Tue Sep 01 18:15:00 GMT 2020view raw
- # Author: ericm <ericm>
- # Date: Fri Jan 14 22:15:51 2000 +0000
- # sprintf(s, "Stardate %2d%03d.%01d",
- # (((t->tm_year + TM_YEAR_BASE) + 377) - 2323),
- # (((t->tm_yday + 1) * 1000) /
- # (365 + IsLeapYear((t->tm_year + TM_YEAR_BASE)))),
- # (((t->tm_hour * 60) + t->tm_min)/144));
- proc IsLeapYear x {
- expr {$x % 4 == 0 && ($x % 100 != 0 || $x % 400 == 0)}
- }
- proc stardate t {
- lassign [lmap x [clock format $t -format {%Y %j %H %M}] {
- string trimleft $x 0
- }] year yday hour min
- puts "$year $yday $hour $min"
- # We don't need to add TM_YEAR_BASE because our years are not counted from
- # 1900. Our $yday starts from 1.
- format "Stardate %2d%03d.%01d" [expr {
- $year + 377 - 2323
- }] [expr {
- $yday * 1000 / (365 + [IsLeapYear $year])
- }] [expr {
- ($hour * 60 + $min) / 144
- }]
- }