Allow for 2 digit years.
Y2K is sufficiently long ago, why not invite a Y2.1K bug? :-P
This commit is contained in:
@@ -5,8 +5,13 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
#include <Alepha/ProgramOptions.h>
|
||||
|
||||
#include <Alepha/Utility/enroll.h>
|
||||
|
||||
#include "Entry.h"
|
||||
|
||||
|
||||
auto
|
||||
getEntries( const std::filesystem::path where )
|
||||
{
|
||||
@@ -31,26 +36,48 @@ getEntries( const std::filesystem::path where )
|
||||
return entries;
|
||||
}
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
namespace C
|
||||
{
|
||||
constexpr int sizeWidth= 14;
|
||||
constexpr int dateWidth= "1982-12-21"s.size();
|
||||
constexpr int shortDateWidth= "82-12-21"s.size();
|
||||
constexpr int timeWidth= "12:34"s.size();
|
||||
constexpr int modeBitsWidth= "drwxrwxrwx"s.size();
|
||||
}
|
||||
|
||||
namespace O
|
||||
{
|
||||
bool twoDigitDate= false;
|
||||
|
||||
auto init= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
using namespace Alepha::ProgramOptions_m;
|
||||
|
||||
--"short-date"_option << twoDigitDate << "Use short 2-digit years in date stamps";
|
||||
};
|
||||
}
|
||||
|
||||
inline int
|
||||
trimYear( const int year )
|
||||
{
|
||||
if( O::twoDigitDate ) return year % 100;
|
||||
else return year;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main( const int argcnt, const char *const argvec[] )
|
||||
{
|
||||
std::filesystem::path where="./";
|
||||
const auto args= Alepha::handleOptions( argcnt, argvec );
|
||||
|
||||
const auto entries= getEntries( where );
|
||||
|
||||
const auto widest= std::max_element( begin( entries ), end( entries ),
|
||||
[]( const auto &lhs, const auto &rhs ) { return lhs.name.size() < rhs.name.size(); } )->name.size();
|
||||
|
||||
const int rowWidth= widest + C::filePadding + C::sizeWidth + 2 + 10 + 2 + C::dateWidth + 1 + C::timeWidth;
|
||||
const int rowWidth= widest + C::filePadding + C::sizeWidth + 1 + C::modeBitsWidth + 2 + ( O::twoDigitDate ? C::shortDateWidth : C::dateWidth )+ 1 + C::timeWidth;
|
||||
|
||||
std::cout << "[1;36;96m";
|
||||
for( int i= 0; i < rowWidth; ++i ) std::cout << "\u2500";
|
||||
@@ -83,7 +110,7 @@ main()
|
||||
|
||||
// Date
|
||||
std::cout << "\e[1;31;91m";
|
||||
std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.year % 10000 << '-';
|
||||
std::cout << std::setw( 2 ) << std::setfill( '0' ) << trimYear( entry.year % 10000 ) << '-';
|
||||
std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.month << '-';
|
||||
std::cout << std::setw( 2 ) << std::setfill( '0' ) << entry.day;
|
||||
std::cout << "\e[m";
|
||||
|
||||
Reference in New Issue
Block a user