datefmt

format unix timestamps over stdin
git clone git://jb55.com/datefmt
Log | Files | Refs | README | LICENSE

commit 74d55a0284ef43953e77e8aca0714d97fa706624
parent 8e87dad0f316295f12b1d304c953c4e69c9ddce6
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  5 Dec 2021 15:41:27 -0800

prepare for 0.2 release

Diffstat:
D.envrc | 1-
M.gitignore | 7+++++++
ACHANGELOG.md | 8++++++++
MMakefile | 23++++++++++++++++++-----
MREADME | 1+
Mdatefmt.c | 2+-
Ddefault.nix | 10----------
Adoc/datefmt.1 | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Adoc/datefmt.scd | 37+++++++++++++++++++++++++++++++++++++
9 files changed, 124 insertions(+), 17 deletions(-)

diff --git a/.envrc b/.envrc @@ -1 +0,0 @@ -use nix diff --git a/.gitignore b/.gitignore @@ -1 +1,8 @@ /datefmt +/tags +/.build-result +/.buildcmd +/.direnv +/dist +/.envrc +/default.nix diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -0,0 +1,8 @@ + +# Changelog + +## 0.2 + +- Added changelog :) +- Added manpage +- Added `--ms` option to format millisecon timestamps diff --git a/Makefile b/Makefile @@ -2,14 +2,27 @@ CFLAGS = -g -Wall -Werror -std=c99 PREFIX ?= /usr -all: datefmt +all: datefmt docs + +docs: doc/datefmt.1 README + +README: datefmt + ./datefmt --help > $@ + +dist: + @mkdir -p dist + @grep '^#define VERSION' datefmt.c | sed -En 's,.*"([^"]+)".*,\1,p' | xargs -I{} git archive HEAD --format tar.gz --prefix datefmt-{}/ -o dist/datefmt-{}.tar.gz + @ls -dt dist/* | head -n1 | xargs echo "tgz " datefmt: datefmt.c $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) -install: datefmt - mkdir -p $(PREFIX)/bin - cp datefmt $(PREFIX)/bin +install: datefmt docs + install -Dm644 doc/datefmt.1 $(PREFIX)/share/man/man1/gmnisrv.1 + install -Dm755 datefmt $(PREFIX)/bin/datefmt + +doc/datefmt.1: doc/datefmt.scd + scdoc < $^ > $@ clean: rm -f datefmt @@ -17,4 +30,4 @@ clean: tags: ctags datefmt.c -.PHONY: install clean +.PHONY: install clean dist diff --git a/README b/README @@ -7,6 +7,7 @@ format unix timestamps from stdin -f, --future only format timestamps in the future -p, --past only format timestamps in the past --version display version information and exit + -m, --ms interpret timestamps as milliseconds instead of seconds FORMAT a strftime format string, defaults to '%F %R' diff --git a/datefmt.c b/datefmt.c @@ -5,7 +5,7 @@ #include <time.h> #include <string.h> -#define VERSION "0.1.1" +#define VERSION "0.2" enum state { BEGIN, diff --git a/default.nix b/default.nix @@ -1,10 +0,0 @@ -{ pkgs ? import <nixpkgs> {} }: -with pkgs; -stdenv.mkDerivation { - pname = "datefmt"; - version = "0.1.1"; - - makeFlags = "PREFIX=$(out)"; - - src = ./.; -} diff --git a/doc/datefmt.1 b/doc/datefmt.1 @@ -0,0 +1,52 @@ +.\" Generated by scdoc 1.11.1 +.\" Complete documentation for this program is not available as a GNU info page +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.nh +.ad l +.\" Begin generated content: +.TH "datefmt" "1" "1980-01-01" +.P +.SH NAME +.P +datefmt - format timestamps in text streams +.P +.SH SYNPOSIS +.P +\fBdatefmt\fR [--after timestamp] [--before timestamp] [--future] [--past] [--version] [--ms] +.P +.SH DESCRIPTION +.P +\fBdatefmt\fR is a tool that formats timestamps in text streams.\& For example, +if you have a log file with unix timestamps, you can pipe it to datefmt +to convert these timestamps into formatted dates.\& +.P +.SH OPTIONS +.P +\fB-p, --past\fR +.RS 4 +only format timestamps in the past +.P +.RE +\fB-f, --future\fR +.RS 4 +only format timestamps in the future +.P +.RE +\fB--version\fR +.RS 4 +display version and exit +.P +.RE +\fB-m, --ms\fR +.RS 4 +interpret timestamps as milliseconds instead of seconds +.P +.RE +.SH FORMAT +.P +a strftime(3) format string.\& defaults to '%F %R' +.P +.SH EXAMPLE +.P +datefmt --after $(date -d yesterday +%s) %R < log.\&txt diff --git a/doc/datefmt.scd b/doc/datefmt.scd @@ -0,0 +1,37 @@ +datefmt(1) + +# NAME + +datefmt - format timestamps in text streams + +# SYNPOSIS + +*datefmt* [--after timestamp] [--before timestamp] [--future] [--past] [--version] [--ms] + +# DESCRIPTION + +*datefmt* is a tool that formats timestamps in text streams. For example, +if you have a log file with unix timestamps, you can pipe it to datefmt +to convert these timestamps into formatted dates. + +# OPTIONS + +*-p, --past* + only format timestamps in the past + +*-f, --future* + only format timestamps in the future + +*--version* + display version and exit + +*-m, --ms* + interpret timestamps as milliseconds instead of seconds + +# FORMAT + +a strftime(3) format string. defaults to '%F %R' + +# EXAMPLE + +datefmt --after $(date -d yesterday +%s) %R < log.txt