Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

higaski/Jidai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jidai

Jidai is a miniature single header library for generating compilation time stamps from the standard preprocessor defines _DATE_ and _TIME_.

The lib comes with two different functions.

One which returns the compilation time as plain struct with integer values for date and time.

  constexpr CompilationTime make_compilation_time();

  struct CompilationTime {
    uint8_t day{};
    uint8_t month{};
    uint16_t year{};
    uint8_t hour{};
    uint8_t minute{};
    uint8_t second{};
  };

And one which returns a unix time stamp since an epoch passed in. The default here is the classic unix epoch 1/1/1970.

  inline constexpr CompilationTime default_epoch{.day = 1, .month = 1, .year = 1970};

  template<typename T = time_t>
  constexpr T make_unix_compilation_time(CompilationTime epoch = default_epoch);

The src/test folder contains a little test case which i checked against the unix time stamp converter on unixtimestamp.com.

  #include <iostream>
  #include "jidai.hpp"

  int main() {
    constexpr auto ct{jidai::make_compilation_time()};
    constexpr auto ut{jidai::make_unix_compilation_time()};
    
    std::cout << "Test compiled at " << (int)ct.day << "/" 
              << (int)ct.month << "/" << (int)ct.year << " " 
              << (int)ct.hour << ":" << (int)ct.minute << ":" 
              << (int)ct.second << " which equals " << ut 
              << "seconds since 1/1/1970.\n";
  }

About

Compilation time stamps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published