Code Monkey home page Code Monkey logo

too-many-timestamps's Introduction

Too many Timestamps

Simple command line tool to interpret and convert UNIX timestamps

Usage

Current time

The actual command is called timestamps. When run with no arguments, it prints info for the current time

timestamps command showing the current time

Timestamp decoding

To decode a timestamp, simply provide it as argument

$ timestamps 1637906683

You can optionally decode other formats by providing the corresponding option

-S, --seconds         Interpret input as seconds (the default)
-M, --milliseconds    Interpret input as milliseconds
-U, --microseconds    Interpret input as microseconds
-N, --nanoseconds     Interpret input as nanoseconds

Snowflake ID decoding

This tool also supports decoding Discord and Twitter IDs ("Snowflake" format) using these options

-D, --discord         Interpret input as a Discord ID
-T, --twitter         Interpret input as a Twitter Snowflake

The non-time info available in Snowflakes is specific to the platform that generated it.

Building and installing

To build this tool, you should not need anything more than an up to date Rust toolchain and running cargo build in the repository.

I have no way to test this, but it seems that compatibility should be complete for all non-embedded platforms that rust supports.

To install, copy the binary wherever you want on the system, and optionally install the completions for your shell.

Copyright

Copyright (C) 2021-2024 0x5c

This program is released under the terms of the Québec Free and Open-Source Licence – Strong Reciprocity (LiLiQ-R+), version 1.1.
See LICENCE for full license text (Français / English).

too-many-timestamps's People

Contributors

0x5c avatar

Stargazers

 avatar

Watchers

 avatar

too-many-timestamps's Issues

IntErrorKind matching whenever rust 1.55.0 lands

let et = match e.kind() {
    std::num::IntErrorKind::Empty
        => "input argument is empty",
    std::num::IntErrorKind::InvalidDigit
        => "invalid charater in timestamp (digits only, ',.' allowed but ignored)",
    std::num::IntErrorKind::PosOverflow
        => "input timestamp too large (is it a real timestamp?)",
    std::num::IntErrorKind::NegOverflow
        => "input timestamp too small [negative] (is it a real timestamp?)",
    _ => panic!(),
}

Add max output precision control

#[derive(Debug)]
pub enum Precision {
    Seconds,
    Millis,
    Micros,
    Nanos,
}

impl fmt::Display for Precision {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let text = match self {
            Self::Seconds => "seconds",
            Self::Millis => "millis",
            Self::Micros => "micros",
            Self::Nanos => "nanos",
        };
        write!(f, "{}", text)
    }
}
.help_heading("OPTIONS")
            .arg(Arg::new("precision")
                .short('p')
                .long("precision")
                .value_name("PRECISION")
                .about("The seconds/millis/etc precision to display")
                .takes_value(true)
                .possible_values(&["seconds", "millis", "micros", "nanos", "auto"])
                .default_value("auto"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.