2021-01-09 12:38:56 -05:00
|
|
|
#!/usr/bin/env perl
|
2022-01-20 15:38:50 -05:00
|
|
|
# -*-coding:utf-8 -*-
|
|
|
|
# Auto updated?
|
|
|
|
# Yes
|
|
|
|
#File :
|
|
|
|
# dayborn
|
2022-01-21 08:38:27 -05:00
|
|
|
#Author:
|
|
|
|
# The-Repo-Club [wayne6324@gmail.com]
|
|
|
|
#Github:
|
2022-01-20 15:38:50 -05:00
|
|
|
# https://github.com/The-Repo-Club/
|
2021-01-09 12:38:56 -05:00
|
|
|
#
|
2022-01-20 15:38:50 -05:00
|
|
|
# Created:
|
|
|
|
# Thu 20 January 2022, 05:40:19 PM [GMT]
|
2022-01-21 08:38:27 -05:00
|
|
|
# Modified:
|
2022-02-06 06:54:40 -05:00
|
|
|
# Sun 23 January 2022, 09:30:37 PM [GMT]
|
2021-01-09 12:38:56 -05:00
|
|
|
#
|
2022-01-20 15:38:50 -05:00
|
|
|
# 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.
|
2021-01-09 12:38:56 -05:00
|
|
|
#
|
2022-01-20 15:38:50 -05:00
|
|
|
# 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.
|
2021-01-09 12:38:56 -05:00
|
|
|
#
|
2022-01-20 15:38:50 -05:00
|
|
|
# Dependencies:
|
2021-01-09 12:38:56 -05:00
|
|
|
# perl (>= 5.22.1-9)
|
2022-01-20 15:38:50 -05:00
|
|
|
#
|
2022-02-06 06:54:40 -05:00
|
|
|
#
|
|
|
|
#
|
2021-01-09 12:38:56 -05:00
|
|
|
|
|
|
|
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{
|
2022-01-19 04:11:28 -05:00
|
|
|
print(qq{Usage: $Progrm [OPTS] [FILE]
|
2021-01-09 12:38:56 -05:00
|
|
|
|
2022-01-19 04:11:28 -05:00
|
|
|
-h, --help - Display this help information.
|
|
|
|
-v, --version - Output the version datestamp.
|
|
|
|
} =~ tr/\t//dr)
|
2021-01-09 12:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while (defined($ARGV[0])){
|
2022-01-19 04:11:28 -05:00
|
|
|
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()
|
2021-01-09 12:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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>){
|
2022-01-19 04:11:28 -05:00
|
|
|
/^# (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()
|
|
|
|
}
|
2021-01-09 12:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|