Posted to tcl by dbohdan at Tue Sep 01 18:15:00 GMT 2020view raw

  1. # Author: ericm <ericm>
  2. # Date: Fri Jan 14 22:15:51 2000 +0000
  3.  
  4. # sprintf(s, "Stardate %2d%03d.%01d",
  5. # (((t->tm_year + TM_YEAR_BASE) + 377) - 2323),
  6. # (((t->tm_yday + 1) * 1000) /
  7. # (365 + IsLeapYear((t->tm_year + TM_YEAR_BASE)))),
  8. # (((t->tm_hour * 60) + t->tm_min)/144));
  9.  
  10. proc IsLeapYear x {
  11. expr {$x % 4 == 0 && ($x % 100 != 0 || $x % 400 == 0)}
  12. }
  13.  
  14. proc stardate t {
  15. lassign [lmap x [clock format $t -format {%Y %j %H %M}] {
  16. string trimleft $x 0
  17. }] year yday hour min
  18. puts "$year $yday $hour $min"
  19.  
  20. # We don't need to add TM_YEAR_BASE because our years are not counted from
  21. # 1900. Our $yday starts from 1.
  22.  
  23. format "Stardate %2d%03d.%01d" [expr {
  24. $year + 377 - 2323
  25. }] [expr {
  26. $yday * 1000 / (365 + [IsLeapYear $year])
  27. }] [expr {
  28. ($hour * 60 + $min) / 144
  29. }]
  30. }
  31.