All Projects → yoshihitoh → ut-cli

yoshihitoh / ut-cli

Licence: MIT license
A command line tool to handle a unix timestamp.

Programming Languages

rust
11053 projects
shell
77523 projects

Projects that are alternatives of or similar to ut-cli

wifiqr
Create a QR code with your Wi-Fi login details
Stars: ✭ 207 (+1492.31%)
Mutual labels:  command-line-tool
smartcd
Expedite your navigation of Linux filesystem.
Stars: ✭ 35 (+169.23%)
Mutual labels:  command-line-tool
swift-commandlinekit
Framework supporting the development of command-line tools in Swift on macOS and Linux. The framework supports managing command-line arguments, provides lightweight functions to deal with escape sequences, and defines an API for reading strings from the terminal.
Stars: ✭ 38 (+192.31%)
Mutual labels:  command-line-tool
grift
swift dependency graph visualizer tool
Stars: ✭ 26 (+100%)
Mutual labels:  command-line-tool
raisin
A simple lightweight set of implementations and bindings for compression algorithms written in Go.
Stars: ✭ 17 (+30.77%)
Mutual labels:  command-line-tool
iconset
A nifty command-line tool to customize macOS icons
Stars: ✭ 29 (+123.08%)
Mutual labels:  command-line-tool
dr scaffold
scaffold django rest apis like a champion 🚀
Stars: ✭ 116 (+792.31%)
Mutual labels:  command-line-tool
gee
🏵 Gee is tool of stdin to each files and stdout. It is similar to the tee command, but there are more functions for convenience. In addition, it was written as go
Stars: ✭ 65 (+400%)
Mutual labels:  command-line-tool
WeConnect-cli
Commandline Interface to interact with the Volkswagen WeConnect Services
Stars: ✭ 27 (+107.69%)
Mutual labels:  command-line-tool
cargo-msrv
🦀 Find the minimum supported Rust version (MSRV) for your project
Stars: ✭ 247 (+1800%)
Mutual labels:  rust-tools
PowerColorLS
PowerShell script to display a colorized directory and file listing with icons
Stars: ✭ 35 (+169.23%)
Mutual labels:  command-line-tool
content-downloader
Python package to download files on any topic in bulk.
Stars: ✭ 102 (+684.62%)
Mutual labels:  command-line-tool
wholesome-cli
Command Line Tool for managing Flutter projects
Stars: ✭ 57 (+338.46%)
Mutual labels:  command-line-tool
diskspace
macOS command line tool to return the available disk space on APFS volumes
Stars: ✭ 123 (+846.15%)
Mutual labels:  command-line-tool
cert human
SSL Certificates for Humans
Stars: ✭ 34 (+161.54%)
Mutual labels:  command-line-tool
dotfiles
dotfiles symbolic links management CLI
Stars: ✭ 156 (+1100%)
Mutual labels:  command-line-tool
okcli
An Oracle-DB command line client
Stars: ✭ 47 (+261.54%)
Mutual labels:  command-line-tool
Infinite-File-Curtailer
Curtail is a utility program that reads stdin and writes to a file bound by size.
Stars: ✭ 23 (+76.92%)
Mutual labels:  command-line-tool
fontman
Manage and update your installed fonts.
Stars: ✭ 20 (+53.85%)
Mutual labels:  command-line-tool
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (+84.62%)
Mutual labels:  command-line-tool

ut

ut is a command line tool to handle a unix timestamp.

Latest Version ci Dependabot

Motivation

There is a number of times to generate/parse unix timestamps. I think date command exists to handle these situations. But there are a few problems that they are small, but vital for me.

  • cannot use same options between macOS and Linux.
  • hard to remember usage. (it might be happen because of above problem.)

That's why I made a new command line tool ut-cli.

I hope ut-cli works well when developers need to use the command which requires timestamps like aws-cli.

Example usage

Search logs from specific time period.

# from yesterday to today
$ aws logs filter-log-events \
    --log-group-name <LOG_GROUP_NAME> \
    --log-stream-names <LOG_STREAM_NAMES> \
    --query <QUERY> \
    --start-time $(ut -p ms g -b yesterday) \
    --end-time $(ut -p ms g -b today)

Installation

If you have rust toolchain, ut-cli can be installed with cargo.

$ cargo install ut-cli

or clone the repository and build it.

$ git clone https://github.com/yoshihitoh/ut-cli
$ cd ut-cli
$ cargo build --release
$ ./target/release/ut --version
ut 0.1.7

Also there are pre-built binary for Linux, macOS and Windows. See releases.

Usage

ut-cli 0.1.7
yoshihitoh <[email protected]>
A command line tool to handle unix timestamp.

USAGE:
    ut [FLAGS] [OPTIONS] <SUBCOMMAND>

FLAGS:
    -u, --utc        Use utc timezone.
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --offset <OFFSET>          Use given value as timezone offset.
    -p, --precision <PRECISION>
            Set the precision of output timestamp.


SUBCOMMANDS:
    generate    Generate unix timestamp with given options.
    help        Prints this message or the help of the given subcommand(s)
    parse       Parse a unix timestamp and print it in human readable format.

You can set options via envrionment variables.

name equiv option example
UT_OFFSET -o/--offset 09:00
UT_PRECISION -p/--precision millisecond
UT_DATETIME_FORMAT - %Y-%m-%d %H:%M

UT_DATETIME_FORMAT follows chrono's datetime specifiers. See the document for details.

# Set variables.
$ export UT_OFFSET='09:00'  # Use JST(+9).
$ export UT_PRECISION=millisecond  # Use timestamps in milliseconds.

# Generate a timestamp.
$ ut g
1588059756238

# Parse a timestamp.
$ echo 1588059756238 | ut p
2020-04-28 16:42:36.238 (+09:00)

# Change custom format and timezone.
$ export UT_DATETIME_FORMAT="%m/%d/%Y"
$ echo 1588059756238 | ut --offset=-7 p
04/28/2020

is equivalent to

$ ut -o '09:00' -p millisecond p $(ut -o '09:00' -p millisecond g)

There are two subcommands available for now.

Generate a unix timestamp

Generate a unix timestamp of the midnight of today.

$ ut generate -b today
1560870000

# You can use `-p` option to show it in millisecond.
$ ut -p ms generate -b today
1560870000000

You can specify time deltas with -d option.

# 3days, 12hours, 30minutes later from the midnight of today.
$ ut g -b today -d 3day -d 12hour -d 30minute
1561174200

# You can use short name on time unit.
$ ut g -b today -d 3d -d 12h -d 30min
1561174200

# You can modify a timestamp with a timestamp argument.
$ ut g -d 1min 1561174200
1561174260    # 1min(=60second) difference.

Parse a unix timestamp

Parse a unix timestamp and print it in human readable format.

$ ut p $(ut g -b today)
2019-06-19 00:00:00 (+09:00)

# You can parse timestamp in milliseconds.
$ ut -p ms p $(ut -p ms g -b today -d 11h -d 22min -d 33s -d 444ms)
2019-06-19 11:22:33.444 (+09:00)

Change timezone

Local timezone

If you don't set timezone options, ut command uses local timezone.

In Japan(UTC+9):

$ ut g --ymd 2019-06-24
1561302000

$ ut p 1561302000
2019-06-24 00:00:00 (+09:00)

You can use -u or --utc option to use UTC timezone.

$ ut --utc p 1561302000
2019-06-23 15:00:00 (UTC)

You can use fixed offset timezone on any environment.

# Generate PST timestamp
$ ut -o -8 g --ymd 2019-06-24
1561363200

# Parse as PST timestamp
$ ut -o -8 p 1561363200
2019-06-24 00:00:00 (-08:00)

# Parse as UTC timestamp
$ ut -o 0 p 1561363200
2019-06-24 08:00:00 (+00:00)

TODO

  • Add more information on README
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].