mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-12-01 03:38:28 -05:00
5860bc6567
Signed-off-by: The-Repo-Club <wayne6324@gmail.com>
110 lines
2.6 KiB
Perl
Executable File
110 lines
2.6 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
# -*-coding:utf-8 -*-
|
|
# Auto updated?
|
|
# Yes
|
|
#File :
|
|
# dayborn
|
|
#Author:
|
|
# The-Repo-Club [wayne6324@gmail.com]
|
|
#Github:
|
|
# https://github.com/The-Repo-Club/
|
|
#
|
|
# Created:
|
|
# Thu 20 January 2022, 05:40:19 PM [GMT]
|
|
# Modified:
|
|
# Sun 23 January 2022, 09:30:37 PM [GMT]
|
|
#
|
|
# Description:
|
|
# 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)
|