Skip to content

Instantly share code, notes, and snippets.

@insom insom/
Created Jun 3, 2015

What would you like to do?
Swatch Internet Time patched into strftime


Compile as above, then add it to any program with LD_PRELOAD=<absolute-path-to-so-file>, like:

LD_PRELOAD=/home/insom/ irc

(And in irssi just issue /SET TIMESTAMP_FORMAT {BEAT} to switch your status bar and timestamp entries to the One True Internet Time).

#define _GNU_SOURCE
#include <sys/types.h>
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
static size_t (*real_strftime)(char *s, size_t max, const char *format, const struct tm *tm) = NULL;
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) {
char result[5] = {0};
real_strftime = dlsym(RTLD_NEXT, "strftime");
time_t t = mktime((struct tm *)tm);
t = t + 3600; // Add an hour to make into BMT
struct tm *bt = gmtime(&t);
double sex = (bt->tm_hour * 3600) + (bt->tm_min * 60) + bt->tm_sec;
int beats = (int)(10 * (sex / 864)) % 1000;
sprintf(result, "@%.3d", beats);
char *new_format = strdup(format);
char *dest = strstr(new_format, "BEAT");
if(dest != NULL) {
strncpy(dest, result, 4);
size_t rv = real_strftime(s, max, new_format, tm);
return rv;
gcc -shared -fPIC beat.c -ldl -o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.