-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtm
executable file
·720 lines (633 loc) · 20.5 KB
/
tm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
#!/usr/bin/perl -w
# Timemachine -- written by Uwe Drechsel
#
my $version=3.6;
#
# 3.9 2018-10-26 Added color output using Term::ANSIColor
# 3.8 2017-01-12 Sanity check if login time > current timeo to
# find forgotten logout on previous day
# 3.7 2018-01-11 Disabled currently unused fields in report
# 3.6 2017-03-20 Added option -be to print single day
# 3.5 2017-02-03 Print data lines when -t is used
# 3.4 2016-12-22 Allow e.g. "24.12" as begin or end date. Or just "24"
# 3.3 2004-06-14 Converted everything to UTF8
# 3.2 2004-06-14 UTF8 Fix
# 3.1 2003-04-09 Fixed day overflow in report with overtime < 24 h
# 3.0 2002-11-20 Now the daterange can be given by weeknumber
# 2.94 2002-01-23 Changed output from Day::HH::MM to HH:MM
# 2.93 2002-01-02 Fixed little bug in call to DayOfWeek
# 2.92 2001-12-29 Replaced Functions from Date::Calc
# 2.91 2001-12-28 started removing Date::Calc, due to problems
# with subtracting times at Freizeitausgleich
# New: time2daytime
# 2.9 2001-12-11 Moved data files to $HOME
# 2.8 2001-12-06 Fixed bug in grep
# 2.7 2001-12-05 Test if $EDITOR is set and files exist
# 2.6 2001-12-05 Adding of comments works now
#
# 2.05 2001-10-24 comment with -c
# 2.04 2001-07-01 Remaining vacation
# 2.03 2001-06-14 -x to mark overtime
# 2.02 2000-12-04 report is its own function now
# 2.01 2000-12-01 rewrite of analyze
# 1.02 2000-11-28 Getopt::Long, introduced #Urlaub and #Freizeitausgleich
# 1.01 2000-11-27 -f reads a file
# 1.00 2000-10-04 first version
#
#
# Requested Features:
# - Cost centers
# - alias for comments
#
# Dataformats:
#
# Time Seconds (signed integer)
# Daytime String "[DAYSd ]hh:mm:ss"
# Day String "Day:MONTH:YEAR" (German date format)
# Day String "YYYYMMDD" (STTS date format)
#
# Todo:
# - Replace old timeformats by the new ones (above) see ### xxx
# - Remove/rewrite
# * Use of Date::Calc functions
# - check, if Freizeitausgleich calculation is correct now
# .tmdata is already converted now.
#use strict;
use Date::Calc qw (:all); # xxx
use Term::ANSIColor qw(:constants);
use Getopt::Long;
GetOptions (
"b=s"=> \$opt_begin,
"be=s"=> \$opt_begin_end,
"c=s"=> \$opt_comment,
"e=s"=> \$opt_end,
"d!" => \$opt_debug,
"f=s" => \$opt_file,
"g=s"=> \$opt_grep,
"h!" => \$opt_usage,
"i!" => \$opt_enter,
"o!" => \$opt_leave,
"l!" => \$opt_lesson,
"s!" => \$opt_sze,
"t!" => \$opt_today,
"v!" => \$opt_edit,
"w=s"=> \$opt_week,
"x!" => \$opt_x ) || usage ();
# Momentanes Datum und Zeit
$Yn=`date +%Y`; chop ($Yn);
$Mn=`date +%m`; chop ($Mn);
$Dn=`date +%d`; chop ($Dn);
$hn=`date +%k`; chop ($hn);
$mn=`date +%M`; chop ($mn);
$sn=`date +%S`; chop ($sn);
# Letzte Anfangszeit (für sanity check, aus analyze)
my $h_login;
my $m_login;
my $s_login;
# Global variables
my ($Db,$Mb,$Yb,$De,$Me,$Ye); # Begin and end of daterange
my ($working); # work in progress...?
my ($Ds,$hs,$ms,$ss); # Sum of working time
my ($Yl,$Ml,$Dl); # last date
my ($work); # number working days
my ($urlaub); # number of vacation days
my ($freizeit); # number of days with "Freizeitausgleich"
# Filenames
my $DATAFILENAME = ".tmdata";
my $COMMFILENAME = ".tmcomment";
my ($DATAFILE) = "$ENV{'HOME'}/$DATAFILENAME";
my ($COMMFILE) = "$ENV{'HOME'}/$COMMFILENAME";
if ($opt_edit) { edit ($DATAFILE); }
if ($opt_usage) {
$0 =~ s#.*/##g;
print <<Helpende;
Timemachine written by Uwe Drechsel - Version $version
usage: $0 [-h][-f filenames][comment]
-h help
-f Filename
-g grep befor generating a report e.g. grep for a comment
-i in
-o out
-c comment and new login (comment is added after loggin out)
-x extra worktime (doesn't count as regular workday and is marked with *)
-l Lesson English (ends session with §Lesson English§)
-b Begin Daterange (format DD or DD.MM or DD.MM.YYYY. default: today)
-e Ende Daterange (format DD or DD.MM or DD.MM.YYYY. default: today)
-be Begin and end daterange (format DD or DD.MM or DD.MM.YYYY. default: today)
-s SZE-entries
-t worktime today
-v open data in \$EDITOR (or in vi)
-w week (sets range for the week of the actual year)
-d Debug Mode
Installation:
Please install perl-Date-Calc.rpm
and touch the DATAFILE, e.g.
touch \$HOME/$DATAFILENAME
Files:
Timemachine uses two files: DATAFILE and COMMFILE.
DATAFILE=\$HOME/$DATAFILENAME
is used to store the information about logins, logouts, comments.
(Before the first use of timemachine you should create it by
touch \$HOME/$DATAFILENAME)
In this file you have:
*
extra worktime (doesn't count as regular workday and
is marked with *)
§+time§ and §-time§
are added/subtracted from the worktime
§Urlaub--§ and §Urlaub+=123§
modify the vacation days
§Freizeitausgleich§
increases the days for "Freizeitausgleich" and starts
a new workday
"this is not important"
is ignored by timemachine, but can be used to grep for
certain lines with the -g option
COMMFILE=\$HOME/$COMMFILENAME
is used to save the comment for writing it later to DATAFILE
Helpende
exit;
}
# Set Range. Default 26.1.1970-today
if ($opt_week) {
($Yb,$Mb,$Db)=Monday_of_Week($opt_week,$Yn);
($Ye,$Me,$De)=Add_Delta_Days($Yb,$Mb,$Db,6);
#print "Week $opt_week: $Db.$Mb.$Yb - $De.$Me.$Ye\n";
} else {
# Don't use -b and -e if -w is used...
if ($opt_begin) {
($Db, $Mb, $Yb) = smartDate ($opt_begin);
} else {
$Db=26;$Mb=1,$Yb=1970;
}
if ($opt_end) {
($De, $Me, $Ye) = smartDate ($opt_end);
} elsif ($opt_today)
{$Db=$Dn;$Mb=$Mn,$Yb=$Yn; $De=$Dn;$Me=$Mn,$Ye=$Yn;}
elsif ($opt_begin_end) {
($Db, $Mb, $Yb) = smartDate ($opt_begin_end);
($De, $Me, $Ye) = smartDate ($opt_begin_end);
if (!$opt_grep) {
# Show everything, if no explicit grep is set
$opt_grep = ".";
}
} else
{$De=$Dn;$Me=$Mn,$Ye=$Yn;}
}
# Work on given file or default-file
if ($opt_file) {
$DATAFILE=$opt_file;
}
analyze($Db,$Mb,$Yb,$De,$Me,$Ye);
if ($opt_lesson){
if ($working) {
# in: leave first
leave ($DATAFILE);
}
open (AFH,">>$DATAFILE") or die "Couldn't open $DATAFILE!\n";
$out=DayOfWeek("$Dn.$Mn.$Yn");
$out=$out . sprintf (" %02i.%02i.%04i",$Dn,$Mn,$Yn);
$out = $out . " §Englisch§\n";
print AFH $out;
close (AFH) or die "Error while closing $DATAFILE!\n";
$opt_enter="";
$opt_leave="";
$opt_comment="";
}
if ($opt_enter) { enter ($DATAFILE); }
if ($opt_leave) { leave ($DATAFILE); }
# Write comment if there are arguments left
if ($#ARGV>=0) { $opt_comment=$ARGV[0]; }
# Write comment if -c option is given
if ($opt_comment) {
if ($working) {
leave ($DATAFILE);
}
open (AFH,,">$COMMFILE") or die "Couldn't open $COMMFILE!\n";
print AFH $opt_comment;
close (AFH) or die "Error while closing $COMMFILE!\n";
enter ($DATAFILE);
} elsif ($opt_enter) {
system ("rm -f $COMMFILE");
}
report();
exit;
########################################################
sub kurzarbeit{ # Ist Datum in KA-Zeitraum?
########################################################
my ($D0,$M0,$Y0)=@_;
return daterange (1,3,2009,$D0,$M0,$Y0,31,10,2009);
}
########################################################
sub DayOfWeek { # locale's abbreviated weekday name
########################################################
# see also for Date::Calc
# Day_of_Week_Abbreviation (Day_of_Week($Y,$M,$D)
my ($date)=$_[0];
$date=~/([0-9]+)\.([0-9]+)\.([0-9]+)/;
$date= `date -d \"$3-$2-$1\" +%a`;
chop ($date);
return $date;
}
########################################################
sub smartDate { # allow e.g. 24.12. or just 24 for date
########################################################
my ($date) = @_;
my @a;
$date =~ /\s*([0-9]+)/;
$a[0] = defined($1) ? $1: $Dn;
$date =~ /\s*([0-9]+)\.([0-9]+)/;
$a[1] = defined($2) ? $2: $Mn;
$date =~ /\s*([0-9]+)\.([0-9]+)\.([0-9]+)/;
$a[2] = defined($3) ? $3: $Yn;
return @a;
}
########################################################
sub tstring { # time to string
### xxx
########################################################
my ($s);
$D=$_[0];
$M=$_[1];
$Y=$_[2];
$h=$_[3];
$m=$_[4];
$S=$_[5];
$s=DayOfWeek("$D.$M.$Y");
$s="$s $D.$M.$Y $h:$m:$S";
return $s;
}
########################################################
sub time2text { # Zeit h,m,s -> String
### xxx
########################################################
my ($h,$m,$s)=@_;
return sprintf( "%02i:%02i:%02i",$h,$m,$s);
}
########################################################
sub time2shorttext { # Zeit h,m -> String
### xxx
########################################################
my ($h,$m)=@_;
return sprintf( "%02i:%02i",$h,$m);
}
########################################################
sub timeint2text { # Zeitintervall D,h,m,s -> String
### xxx
########################################################
my ($D,$h,$m,$s,$sign)=@_;
my ($vz)=" "; # falls nur 4 Parameter: vz=" "
if ( defined $sign) { # sonst evtl. vz="-" oder " "
if ($sign<0)
{$vz="-";}
}
return $vz . sprintf( "%02id %02i:%02i:%02i",$D,$h,$m,$s);
}
########################################################
sub timeint2shorttext { # Zeitintervall D,h,m -> String
### xxx
########################################################
my ($D,$h,$m,$s,$sign)=@_;
my ($vz)=" "; # falls nur 4 Parameter: vz=" "
if ( defined $sign) { # sonst evtl. vz="-" oder " "
if ($sign<0)
{$vz="-";}
}
return $vz . sprintf( "%02id %02i:%02i",$D,$h,$m);
}
########################################################
sub date2text { # Datum D,M,Y -> String
### xxx
########################################################
my ($D,$M,$Y)=@_;
return sprintf( "%02i.%02i.%04i",$D,$M,$Y);
}
########################################################
sub before_date { # Date 0 <= date 1 ?
### xxx
########################################################
my ($D0,$M0,$Y0,$D1,$M1,$Y1)=@_;
return 0 if ($Y0>$Y1);
return 1 if ($Y0<$Y1);
return 0 if ($M0>$M1);
return 1 if ($M0<$M1);
return 0 if ($D0>$D1);
return 1;
}
########################################################
sub daterange { # Date 1 in Range 0-2?
### xxx
########################################################
my ($D0,$M0,$Y0,$D1,$M1,$Y1,$D2,$M2,$Y2)=@_;
return 1 if ( (before_date($D0,$M0,$Y0, $D1,$M1,$Y1) ) &&
(before_date($D1,$M1,$Y1, $D2,$M2,$Y2) ) );
return 0;
}
########################################################
sub add_time { # Zeit addieren D,h,m,s,Dd,hd,md,sd
### xxx
########################################################
my ($D,$h,$m,$s,$Dd,$hd,$md,$sd)=@_;
use integer;
$s=$s+$sd; if ($s>59) {$m=$m+$s/60; $s=$s % 60;}
$m=$m+$md; if ($m>59) {$h=$h+$m/60; $m=$m % 60;}
$h=$h+$hd; if ($h>23) {$D=$D+$h/24; $h=$h % 24;}
$D=$D+$Dd;
return ($D,$h,$m,$s);
no integer;
}
########################################################
sub sub_time { # Zeit subtrahieren D0,h0,m0,s0,D1,h1,m1,s1
### xxx
########################################################
my ($D0,$h0,$m0,$s0,$D1,$h1,$m1,$s1)=@_;
my ($sign)=1;
use integer;
#erstmal in s umwandeln
my ($sek0,$sek1, $Dd,$hd,$md,$sd);
$sek0=$D0*24*3600 + $h0*3600 +$m0*60 +$s0;
$sek1=$D1*24*3600 + $h1*3600 +$m1*60 +$s1;
if ($sek1>$sek0) { # negatives Vorzeichen
$sign=$sek1;
$sek1=$sek0;
$sek0=$sign;
$sign=-1;
}
#Differenz berechnen
$sd=$sek0-$sek1;
$Dd=$sd / 86400; # Anzahl s pro Tag
$sd=$sd % 86400;
$hd=$sd / 3600;
$sd=$sd % 3600;
$md=$sd / 60;
$sd=$sd % 60;
return ($Dd,$hd,$md,$sd,$sign);
no integer;
}
########################################################
sub time2daytime { # seconds to daytime format
########################################################
my ($s)=@_;
my ($Dd,$hd,$md,$sd);
my ($sign)=1;
use integer;
$sign=-1 if $s <0;
$Dd=$s / 86400; # Anzahl s pro Tag
$sd=$s % 86400;
$hd=$s / 3600;
$sd=$s % 3600;
$md=$s / 60;
$sd=$s % 60;
return ($Dd,$hd,$md,$sd,$sign);
no integer;
}
########################################################
sub analyze{ # FILE auswerten
########################################################
my (@lines)=readfile($DATAFILE); # File mit Zeitangaben
my ($Yb,$Mb,$Db); # Beginn Zeitraum
$Db=$_[0];
$Mb=$_[1];
$Yb=$_[2];
my ($Ye,$Me,$De); # Ende Zeitraum
$De=$_[3];
$Me=$_[4];
$Ye=$_[5];
my ($Y0,$M0,$D0,$h0,$m0,$s0); # Anfangszeit in Zeile
my ($Y1,$M1,$D1,$h1,$m1,$s1); # Endzeit in Zeile
my ( $Dd,$hd,$md,$sd); # Differenzeit in Zeile
my ( $Dt,$ht,$mt,$st); # Summe pro Tag
($Ds,$hs,$ms,$ss)=(0,0,0,0);
($Dt,$ht,$mt,$st)=(0,0,0,0);
($Dd,$hd,$md,$sd)=(0,0,0,0);
($Yl,$Ml,$Dl)=(0,0,0);
$work=0; # reguläre arbeitstage
$work_ka=0; # arbeitstage in KA
$urlaub=0;
$freizeit=0;
$working=0;
my $s; # Suchstring
if ($opt_grep) { # grep before analyzing
@new=grep {/$opt_grep/} @lines;
@lines=@new;
}
foreach (@lines) {
$xworking=0;
if (/[0-9]/) { # ignore lines without numbers
# Read date
/([0-9]+)\.([0-9]+)\.([0-9]+)/;
$D0=$1; $M0=$2; $Y0=$3;
if (daterange ($Db,$Mb,$Yb, $D0,$M0,$Y0, $De,$Me,$Ye)) {
if ($opt_grep || $opt_today) {
# Show lines if grep is used, just to be sure
print "$_";
}
# Do we have a new day?
if ( ($Dl!=$D0) || ($Ml!=$M0) || ($Yl!=$Y0)) {
if (!/\*/) {
if (kurzarbeit ($D0,$M0,$Y0))
{
$work_ka++;
} else
{
$work++;
}
if ($opt_sze && $Dl!=0) {
print "mysze $Dl.$Ml.$Yl $ht:$mt \n";
}
$Dl=$D0; $Ml=$M0; $Yl=$Y0;
($Dt,$ht,$mt,$st)=(0,0,0,0);
} else {
$xworking=0;
}
}
if (/§/) {
/§(.+)§/;
$s=$1;
if ($s=~/Urlaub--/) {$urlaub--;}
if ($s=~/Urlaub\+=([0-9]+)/) {$urlaub=$urlaub+$1;}
if ($s=~/Freizeitausgleich/) {$freizeit++;}
if ($s=~/\+([0-9]+):([0-9]+):([0-9]+)/) {
($Ds,$hs,$ms,$ss)=add_time
($Ds,$hs,$ms,$ss, 0,$1,$2,$3);
}
if ($s=~/-([0-9]+):([0-9]+):([0-9]+)/) {
($Ds,$hs,$ms,$ss)=sub_time
($Ds,$hs,$ms,$ss, 0,$1,$2,$3);
}
} # End of �
else {
# Anfangszeit auslesen (Datum ist schon da)
if (/([0-9]+):([0-9]+):([0-9]+)/) {
$h0 = $1; $m0 = $2; $s0 = $3;
} else {
if (/([0-9]+):([0-9]+)/) {
$h0 = $1; $m0 = $2; $s0 = 0;
} else {
print "Problem reading start time in $_";
exit;
}
}
# Anfangszeit merken für sanity check
$h_login =$h0;
$m_login =$m0;
$s_login =$s0;
# Endzeit auslesen bzw. auf aktuelle Zeit setzen
if (/>/) {
if (/>([0-9]+):([0-9]+):([0-9]+)/) {
$h1 = $1; $m1 = $2; $s1 = $3;
} else {
if (/>([0-9]+):([0-9]+)/) {
$h1 = $1; $m1 = $2; $s1 = 0;
} else {
print "Problem reading end time in $_";
exit;
}
}
$D1=$D0;$M1=$M0;$Y1=$Y0;
$working =0;
}
else {
($Y1,$M1,$D1,$h1,$m1,$s1) = ($Yn,$Mn,$Dn,$hn,$mn,$sn);
$working=1;
}
# Differenz Anfang->Ende ausrechnen
($Dd,$hd,$md,$sd)=sub_time ($D0,$h0,$m0,$s0,
$D1,$h1,$m1,$s1);
# Summe ausrechnen
($Ds,$hs,$ms,$ss)=add_time($Ds,$hs,$ms,$ss,
$Dd,$hd,$md,$sd);
($Dt,$ht,$mt,$st)=add_time($Dt,$ht,$mt,$st,
$Dd,$hd,$md,$sd);
} # End of no
debug ("Day $Y0-$M0-$D0 workdays: $work (KA: $work_ka) Sum today: $ht:$mt Diff: d=$Dd d $hd:$md:$sd Sum total= $Ds d $hs:$ms:$ss");
} # End of in daterange
} # End of line containing a number
} # End of @lines
} # analyze
########################################################
sub report{ # Report generieren
########################################################
my $c; # used for showing the comment
my @a; # used for showing the comment
if (-f $COMMFILE) {
@a=readfile ($COMMFILE);
$c="\"" . $a[0] . "\"";
} else {
$c=""; # empty string to avoid error at concatenation
}
print "\n";
print "Report ",
date2text($Db,$Mb,$Yb),"-",
date2text($De,$Me,$Ye)," ",
time2text($hn,$mn,$sn),"\n";
print "==========================================\n";
printf " Workdays: %4d \n",$work;
#printf " Kurz-Arbeitstage: %4d \n",$work_ka;
#printf " Resturlaub: %4d \n",$urlaub;
#printf " Freizeitausgleich: %4d \n",$freizeit;
printf " Sum so far: %4d:%02d \n",$Ds*24+$hs,$ms;
# @over is needed until I changed the time format completly:
my @over=sub_time ( $Ds,$hs,$ms,$ss,0,8*($work) + 7*$work_ka,0,0,0);
if ($over[4]<0) {
printf " Overtime: -%2d:%02d\n",($over[1]+24*$over[0]),$over[2];
} else {
printf " Overtime: %4d:%02d\n",($over[1]+24*$over[0]),$over[2];
}
print " Comment: $c\n",
" Status: ";
if (!$working) {
print "out\n";
} else {
if (!$working) {
print "in (No workday) \n";
} else {
print "in \n";
}
}
} # report
########################################################
sub readfile { # Read file
########################################################
my ($filename) =@_;
my (@lines);
open (INFILE, "<$filename") ||
die "File $filename not readable";
@lines=<INFILE>;
return @lines;
}
########################################################
sub debug {
########################################################
if ($opt_debug) {
print "Debug: @_\n";
}
}
########################################################
sub edit { # Edit datafile
########################################################
my ($filename) =@_;
if (defined $ENV{'EDITOR'}) {
system ("$ENV{'EDITOR'} $filename");
} else {
system ("export LANG=C;vi $filename");
}
}
########################################################
sub enter { # Anfang Arbeit
########################################################
my $out;
# Kein Autobuild während meiner Arbeitszeit
#system ("touch /tmp/noautobuild");
#print "I have touched /tmp/noautobuild for your convenience!\n";
if ($working)
{print RED, "\nYou are already working?!\n\n", RESET;}
else {
my ($out);
my ($FILENAME)=@_;
open (AFH,">>$FILENAME") or die "Couldn't open $FILENAME!\n";
$out=DayOfWeek("$Dn.$Mn.$Yn");
$out=$out . sprintf (" %02i.%02i.%04i",$Dn,$Mn,$Yn);
if ($opt_x) {
$out=$out . "*"; # Kein Werktag!
} else {
$out=$out . " ";
}
if ($opt_lesson) { $out = $out . "§Englisch§\n".$out;}
# old long format: $out=$out . sprintf ("%02i:%02i:%02i",$hn,$mn,$sn);
$out=$out . sprintf ("%02i:%02i",$hn,$mn);
print AFH "$out-";
close (AFH) or die "Error while closing $FILENAME!\n";
$working=1;
}
}
########################################################
sub leave { # Ende Arbeit
########################################################
my $out;
my @s;
if (!$working)
{print RED, "\nYou are currently not working?!\n\n", RESET;}
else {
# Sanity check, if we maybe forgot to logout the previous day...
if ($h_login > $hn)
{
print RED, "Forgot to logout on previous day?!\n\n";
print "Current time: $hn:$mn:$sn\n";
print "Login time: $h_login:$m_login:$s_login\n", RESET;
}
my ($out);
my ($FILENAME)=@_;
open (AFH,">>$FILENAME") or die "Couldn't open $FILENAME!\n";
# old long format: $out=">" . sprintf ("%02i:%02i:%02i",$hn,$mn,$sn);
$out=">" . sprintf ("%02i:%02i",$hn,$mn);
# Falls Kommentar vorhanden, diesen anh�ngen
if (-f $COMMFILE) {
@s=readfile ($COMMFILE);
$out=$out . " \"" . $s[0] . "\"";
}
print AFH "$out\n";
close (AFH) or die "Error while closing $FILENAME!\n";
$working=0;
}
}