Zoladate: Custom Timestamp

Date: 2022-09-01
categories: command-line;

I created an alias to generate the datetime and Unix timestamp shown on these blog posts.

Here's the command:

d=`date` && dt=`date -d "$d" +"%s"` && echo "$d (Unix time = $dt)"

I created an alias for myself, zoladate to remember it. At some point for fun, I might add an extension to Zola as a builtin, but at the moment I have other projects that seem more interesting.

Unfortunately, macOS doesn't support the date -d argument, so instead I threw together a quick program in C instead.

#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>

// gcc -std=c11 zoladate.c -o zoladate
int main() {
    time_t seconds_epoch = time(NULL);
    struct tm* cal_time = localtime(&seconds_epoch);
    char buffy[70];
    if (strftime(buffy, sizeof buffy, "%c", cal_time)) {
        printf("%s (Unix time = %ld)\n", buffy, seconds_epoch);
    } 

    exit(EXIT_SUCCESS);
}