shinemic

overtime_indicator

Jan 22nd, 2022 (edited)
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.38 KB | None | 0 0
  1. #! /usr/bin/env perl
  2.  
  3. use v5.10;
  4. no strict;
  5.  
  6. use POSIX(strftime);
  7. use Time::Local(timelocal);
  8. use Time::HiRes qw(gettimeofday usleep);
  9.  
  10. $| = 1;
  11. system('tput civis && clear && echo && echo');
  12.  
  13. @CLOCKS = qw [
  14.     πŸ•› πŸ•§ πŸ• πŸ•œ πŸ•‘ πŸ• πŸ•’ πŸ•ž
  15.     πŸ•“ πŸ•Ÿ πŸ•” πŸ•  πŸ•• πŸ•‘ πŸ•– πŸ•’
  16.     πŸ•— πŸ•£ πŸ•˜ πŸ•€ πŸ•™ πŸ•₯ πŸ•š πŸ•¦
  17. ];
  18.  
  19. $day_of_week = strftime "%u", localtime;
  20. $wage_hour = $day_of_week =~ /[67]/ ? 60 : 45;
  21. if (@ARGV) {
  22.     ($start_time = $ARGV[0]) =~ s/[:,.\s]//g;
  23.     ($h, $m, $s) = ($start_time, 0, 0) if $start_time =~ (/^..?$/);
  24.     ($h, $m, $s) = ($1, $2, 0)  if $start_time =~ (/^(..)(..)$/);
  25.     ($h, $m, $s) = ($1, $2, $3) if $start_time =~ (/^(..)(..)(..)$/);
  26. } else {
  27.     ($h, $m, $s) = $day_of_week =~ /[67]/ ? (10, 0, 0) : (18, 0, 0);
  28. }
  29.  
  30. $start_ts = timelocal($s, $m, $h, (localtime)[3 .. 5]);
  31. $now_ts   = timelocal(localtime);
  32. $start_ts -= 24 * 3600 if $start_ts > $now_ts;
  33.  
  34. while (1) {
  35.     $now_time = strftime "%H:%M:%S", localtime;
  36.     ($now_s, $now_ts_mus) = gettimeofday();
  37.     $total_ts_mus = ($now_s - $start_ts) * 1_000_000 + $now_ts_mus;
  38.     $total_ts_h   = $total_ts_mus / 1_000_000 / 3600;
  39.     $wage_tot     = $total_ts_h * $wage_hour;
  40.     $clock_idx    = $now_s % @CLOCKS;
  41.  
  42.     printf "\r%s$now_time πŸ”¨ε·²εŠ η­%.1f小既 πŸ’°θΎ›θ‹¦θ΄Ή%.4f",
  43.         $CLOCKS[$clock_idx], $total_ts_h, $wage_tot;
  44.     usleep(5_000);
  45. }
  46.  
Add Comment
Please, Sign In to add comment