shinemic

overtime_indicator

Jan 22nd, 2022 (edited)
240
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data Copied