TheRepoClub-DotFiles/localbin/.local/bin/dayborn
2022-01-19 09:11:28 +00:00

102 lines
2.8 KiB
Perl
Executable File

#!/usr/bin/env perl
#cito M:755 O:0 G:0 T:/usr/bin/dayborn
#------------------------------------------------------------------------------
# Path - /usr/bin/dayborn#
# GitHub - https://github.com/The-Repo-Club/
# # Author - The-Repo-Club [wayne6324@gmail.com]
# # Start On - Sun 31 Oct 18:54:42 GMT 2021#
# Modified On - Sun 31 Oct 18:54:42 GMT 2021#
#------------------------------------------------------------------------------
#
# This project was originally called Iteration. The aim was to generate a more
# traditional version number from the delta of the two timestamps, the time the
# project was born, and the time of the last change made.
#
# In the end, it wound up being a nifty little program which simply outputs how
# many days it has been since the project was born, hence the name.
#
# Dependencies:
#
# perl (>= 5.22.1-9)
#------------------------------------------------------------------------------
require Date::Format;
require Time::Piece;
use v5.22.1;
use strict;
use warnings;
use autodie;
use Date::Format 'time2str';
use Time::Piece;
no warnings 'uninitialized';
my $CurVer = '2021-02-01';
my $Progrm = 'dayborn';
sub Usage{
print(qq{Usage: $Progrm [OPTS] [FILE]
-h, --help - Display this help information.
-v, --version - Output the version datestamp.
} =~ tr/\t//dr)
}
while (defined($ARGV[0])){
if ($ARGV[0] =~ '^(--help|-h|-\?)$'){
Usage(1); exit(0)
}elsif ($ARGV[0] =~ '^(--version|-v)$'){
print("$CurVer\n"); exit(0)
}elsif ($ARGV[0] =~ '^-'){
die("Incorrect option(s) specified")
}else{
last
}
shift()
}
scalar(@ARGV) == 1 or die("File name required");
scalar(@ARGV) > 1 and die("Only one file at a time is valid");
-f $ARGV[0] or die("File '$ARGV[0]' not found");
-r $ARGV[0] or die("File '$ARGV[0]' unreadable");
-B $ARGV[0] and die("File '$ARGV[0]' is binary");
open(my $FH, '<', $ARGV[0]);
my ($Start, $Now);
while (<$FH>){
/^# (Start|Modified) / or next;
chomp(my @Arr = split(' '));
# The following format (sans quotes) is expected:
#
# '# Started On - Mon 10 Feb 23:49:15 GMT 2020'
#
if ($Arr[1] eq 'Start') {
$Start = Time::Piece->strptime(
join(' ', @Arr[4,6,5,7,9]), '%a %b %d %T %Z %Y'
)->epoch()
}
# The following format (sans quotes) is expected:
#
# '# Modified On - Tue 11 Feb 01:00:34 GMT 2020'
#
if ($Arr[1] eq 'Modified') {
$Now = Time::Piece->strptime(
join(' ', @Arr[4,6,5,7,9]), '%a %b %d %T %Z %Y'
)->epoch()
}
}
close($FH);
my $Project = ($ARGV[0] =~ m{(?:.*/)?([^/].*)})[0];
my $DeltaDay = ($Now - $Start) / 60 / 60 / 24;
printf("Project '%s' was born %.2f day's ago.\n", $Project, $DeltaDay)