OH4

timestamps

About the timestamps on this site.

Throughout the site you will see timestamp like 7E4B14. Each is a date in hexadecimal: three digits for the year, one for the month and two for the day, so 7E4B14 is 20 November 2020.

Reading one back takes a few lines of C:

Listing 1 · C · 34 lines
#include <stdio.h>

typedef struct OH4_Date OH4_Date;
struct OH4_Date {
  int	Year;
  int	Month;
  int	Day;
};

static OH4_Date OH4_DateFromCode(const char* code) {
  OH4_Date result = { 0 };

  int is_valid = 1;
  int digits[6] = { 0 };
  for (int idx = 0; is_valid && idx < 6; ++idx) {
    char ch = code[idx];
    is_valid = (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F');
    digits[idx] = (ch <= '9') ? (ch - '0') : (ch - 'A' + 10);
  }

  if (is_valid) {
    result.Year = digits[0] * 256 + digits[1] * 16 + digits[2];
    result.Month = digits[3];
    result.Day = digits[4] * 16 + digits[5];
  }

  return( result );
}

int main(void) {
  OH4_Date date = OH4_DateFromCode("7E4B14");
  printf("%04d-%02d-%02d\n", date.Year, date.Month, date.Day);
  return( 0 );
}