rti

Crates.iorti
lib.rsrti
version0.1.6
sourcesrc
created_at2022-04-22 12:48:12.896198
updated_at2023-11-02 12:39:53.91815
descriptionA tool to convert to/from unix epoch times.
homepagehttps://github.com/cforte7/rusty_time_interpreter
repositoryhttps://github.com/cforte7/rusty_time_interpreter
max_upload_size
id572145
size50,042
Christopher Forte (cforte7)

documentation

README

Rusty Time Interpreter (rti)

rti (Rusty Time Interpreter) is a command line tool for converting between unix epoch time and date/time strings. It is written in Rust and should run on any platform.

This tool was inspired by the extremely useful epoch-echo by Ainsley McGrath. While the tool is fantastic, the main issues were speed and portability which inspired me to write this in Rust.

Installation

Currently you can either clone the repo and compile binaries yourself, or download with cargo. Using cargo:

cargo install rti

This will create a globally executable command that can be used in your command line. Note: This has only been tested on macOS and Windows 10.

Usage

rti takes in an arbitrary number of command line arguments, either integer unix epochs or string date/time/datetimes and converts them to the opposite.

$ rti 1 1650627609 2022-04-22\ 11:40:09
1 => 01-01-1970 00:00:01
1650627609 => 04-22-2022 11:40:09
2022-04-22 11:40:09 => 1650627609
Timezone: UTC

There are also special keywords for now, yesterday, tomorrow which will give the epoch time for the current time of today, yesterday, and tomorrow respectively.

// ran at May 10, 2022 at 5:25PM UTC time
$ rti now yesterday tomorrow
now => 1652203517
yesterday => 1652117117
tomorrow => 1652289917
Timezone: UTC

Timezone

rti supports using custom timezone both by setting a persisted configuration and through environment variables. If no timezone is set in your local config or by environment variable, UTC will be used.


// Set custom timezone in config
$ rti set-tz America/New_York

// clear timezone config
$ rti clear-tz

// using TIMEZONE environment variable
$ TIMEZONE=America/Denver rti now

rti timezones are set in the following precedence:

  1. Environment variable
  2. Config
  3. UTC if no config or Env variable is present

Custom Parsing Tokens

rti comes with preset parsing patterns, but you can also add your own datetime tokens to parse. Note that the tokens must be full datetime values (not just time or just date).

See https://docs.rs/chrono/0.4.0/chrono/format/strftime/index.html for details on the syntax.

$ rti add-token "%d-%m-%y %H:%M"
Custom Token added

$ rti view-tokens
Custom datetime tokens:
%d-%m-%y %H:%M

$ rti remove-token "%d-%m-%y %H:%M"
Token removed if it existed: %d-%m-%y %H:%M
Commit count: 90

cargo fmt