belt is a command line app that can show your time from a list of selected time zones

Overview

belt + dateparser

Build Status MIT licensed

belt is a command line app that can show your time from a list of selected time zones. dateparser is a rust library for parsing date strings in commonly used formats.

Run belt to parse a given date:

$ belt 'MAY 12, 2021 16:44 UTC'
+-------------------+---------------------------+
| Zone              | Date & Time               |
+===================+===========================+
| Local             | 2021-05-12 09:44:00 -0700 |
|                   | 1620837840                |
+-------------------+---------------------------+
| UTC               | 2021-05-12 16:44:00 +0000 |
|                   | 2021-05-12 16:44 UTC      |
+-------------------+---------------------------+
| America/Vancouver | 2021-05-12 09:44:00 -0700 |
|                   | 2021-05-12 09:44 PDT      |
+-------------------+---------------------------+
| America/New_York  | 2021-05-12 12:44:00 -0400 |
|                   | 2021-05-12 12:44 EDT      |
+-------------------+---------------------------+
| Europe/London     | 2021-05-12 17:44:00 +0100 |
|                   | 2021-05-12 17:44 BST      |
+-------------------+---------------------------+

Display parsed date in the short form:

# parse a unix epoch timestamp
$ belt 1511648546 --short
2017-11-25 14:22:26 -0800

# or show the current local datetime
$ belt --short
2021-05-15 22:54:34 -0700

Time zones are configurable:

$ belt config --help
belt-config
Configure time zones list

USAGE:
    belt config [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -l, --list       List existing time zones
    -r, --reset      Reset to default list of time zones
    -V, --version    Prints version information

OPTIONS:
    -a, --add <timezone_to_add>          Add a new time zone to the list
    -d, --delete <timezone_to_delete>    Delete a time zone from the list

Installation

MacOS Homebrew or Linuxbrew:

brew tap waltzofpearls/belt
brew install belt

dateparser

Crates.io Doc.rs

Date parsing in belt is powered by dateparser crate, which is a part of this repo.

Accepted date formats

Date string in the following formats can be parsed by belt:

1511648546
1620021848429
1620024872717915000
2021-05-01T01:17:02.604456Z
2017-11-25T22:34:50Z
Wed, 02 Jun 2021 06:31:39 GMT
2019-11-29 08:08:05-08
2021-05-02 23:31:36.0741-07
2021-05-02 23:31:39.12689-07
2019-11-29 08:15:47.624504-08
2021-04-30 21:14:10
2021-04-30 21:14:10.052282
2017-11-25 13:31:15 PST
2017-11-25 13:31 PST
2021-02-21
2021-02-21 PST
01:06:06
4:00pm
6:00 AM
01:06:06 PST
4:00pm PST
6:00 AM PST
May 02, 2021 15:51:31 UTC
May 02, 2021 15:51 UTC
Comments
  • Parse with left-aligned milli/micro/nanoseconds

    Parse with left-aligned milli/micro/nanoseconds

    Hi! I think it's reasonable to always parse times with left-aligned milliseconds - otherwise whatever is after the dot is parsed as nanoseconds, leading to (what I assume are) unexpected results.

    Before the change:

    println!("{:?}", parse_datetime("2022-08-16 19:37:03.123 UTC").unwrap()); 
    // 2022-08-16T19:37:03.000000123Z
    

    After:

    println!("{:?}", parse_datetime("2022-08-16 19:37:03.123 UTC").unwrap()); 
    // 2022-08-16T19:37:03.123Z
    
    opened by gyfis 3
  • Default time for incomplete datetime strings

    Default time for incomplete datetime strings

    QUERY: I'm quite keen to use this library, as I try to migrate from Scala/JVM world to Rust where I can. One of the better (though now really obsolete) libraries in the JVM ecosystem is the Joda datetime handler. What is tripping me up is subtle differences in handling parse for "datetimes" that only contain the date part. For example in scala:

    scala> import org.joda.time.DateTime
     
     DateTime.parse("2021-12-02")
    import org.joda.time.DateTime
    
    scala> 
    scala> res0: org.joda.time.DateTime = 2021-12-02T00:00:00.000Z
    

    whereas in your dateparser, the same kind of parse would yield

    [src/main.rs:161] date1 = 2021-12-02T12:06:22.907945488Z
    

    Looking at the code, I can see that you are using current time as "filler" for those fields that are missing. This seems like a perfectly valid approach, but I'm wondering if you would consider extending the API to support passing arbitrary DateTime values to be used as fillier. That would allow me to replicate the behaviour of Joda a little more easily, without having to do a lot of regex parsing and date truncation in my own code.

    opened by nheitz 3
  • parse returns datetime with time set to current local time

    parse returns datetime with time set to current local time

    Reviving https://github.com/waltzofpearls/belt/issues/16

    I was wondering if you would consider adding a feature or accepting a PR to allow zeroing out of unknown components?

    My use case is I wish to use this parser to parse arbitrary dates where adding the local time makes the dates incorrect. Because I'll be parsing arbitrary data where the input is not under my direct control I will be unable to implement the workaround provided in the previous issue.

    opened by deankarn 2
  • `parse` returns datetime with time set to current local time...

    `parse` returns datetime with time set to current local time...

    ...when calling parse with a plain date string. For example:

    use dateparser::parse;
    use std::error::Error;
    
    fn main() -> Result<(), Box<dyn Error>> {
        let parsed = parse("July 14, 2021")?;
        println!("{:#?}", parsed);
        Ok(())
    }
    

    returns a value like 2021-07-14T22:51:35.983216400Z where the time portion happens to be the current local time.

    Shouldn't it just return 2021-07-14T00:00:00Z?

    Thanks regardless @waltzofpearls !

    opened by jqnatividad 2
  • dateparser: add `parse_with()` for configurable tz and default time

    dateparser: add `parse_with()` for configurable tz and default time

    a date string without time (eg. July 14, 2021) can be parsed into DateTime assigned with local time or midnight at UTC, for example, either 2021-07-14T22:51:35.983216400Z or 2021-07-14T00:00:00Z.

    Resolves https://github.com/waltzofpearls/belt/issues/16

    opened by waltzofpearls 0
  • dateparser: support more formats + parsing on a specific timezone

    dateparser: support more formats + parsing on a specific timezone

    • add more internal parsing functions for more formats
    • add another function to parse with a specific timezone instead of the default local timezone
    • create a new parse struct and move all the internal parsing functions into the struct's impl block as methods
    opened by waltzofpearls 0
  • dateparser: changed return type and implemented fromstr

    dateparser: changed return type and implemented fromstr

    • return type for parse() function changed from Option<DateTime> to Result<DateTime>, error that has to bubble up will be returned, for example, regex parsing error or no matching format to parse input date str
    • newtype DateTimeUtc(DateTime) and implemented FromStr for DateTimeUtc, so in addition to calling parse(input), input.parse::() works too
    opened by waltzofpearls 0
  • Feature Request: replace `chrono`

    Feature Request: replace `chrono`

    Given chrono's unresolved security advisory - https://rustsec.org/advisories/RUSTSEC-2020-0159,

    It'd be nice if dateparser is re-implemented without it.

    opened by jqnatividad 1
Releases(v0.1.7)
Owner
Rollie Ma
Gopher, rustacean, pythonist, amateur archaeologist && corgi wrangler
Rollie Ma
JiaShiwen 12 Nov 5, 2022
A todo list app that indexes your app to find TODO:'s

forgot A todo list app that indexes your app to find TODO:'s Usage to list all your todos forgot list list all your todos ignoring search in ./target,

null 2 Oct 6, 2022
Fast command-line application to show the moon phase

moon-phases Command-line application to show the moon phase for a given date and time, as a text string, emoji, or numeric value. It can also show the

mirrorwitch 3 Oct 7, 2023
App to collect ram/cpu usage from OS and show it in pretty graphs

System info collector This is simple app to collect data about system cpu and memory usage over time. After collecting results into csv file, html fil

Rafał Mikrut 3 Jul 11, 2023
A command-line tool to generate a list of required missing Android OS Project blobs.

aosp-missing-blobs aosp-missing-blobs is a nifty tool to identify required blobs (.so) that are missing from AOSP ROM builds, and to show which existi

Josh 176 Dec 16, 2022
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
🚩 Show sensitive command summary when open a new terminal

?? Show sensitive command summary when open a new terminal ?? Clear sensitive commands from shell history ?? Stash your history command before present

Rusty Ferris Club 161 Dec 26, 2022
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Aldrin Zigmund Cortez Velasco 18 Oct 24, 2022
Animated app icons in your Dock that can run an arbitrary shell script when clicked.

Live App Icon for Mac Animated app icons in your Dock that can run an arbitrary shell script when clicked. Requirements macOS 13 (Ventura) or higher X

Daichi Fujita 13 Jun 8, 2023
🎨✨ Show off your soothing color palette

?? Show off your soothing color palette ✨ Palettes · install · contribute · Gratitute ?? Palettes Rust C Lua Ruby Go sh js ?? install Installing this

BinaryBrainiacs 4 Jan 28, 2023
Generate a vanity address (`juno1wynd...`) to show your support for WYND DAO

WYND Generator When you generate a new mnemonic, it is very random (must be to be secure), and you cannot predict the address you will get. However, i

null 9 Dec 8, 2022
Show HTML content "inside" your egui rendered application

hframe Show HTML content "inside" your egui rendered application. "hframe" stands for "HTML Frame". Note: hframe only works when the application is co

Franco Profeti 3 Feb 26, 2024
CLI app to display list of trending anime, music charts or recommend anime to watch or song to listen to.

Description Anitrendz is a cli app that uses data from the anitiop api to list the top anime and songs or recommend a random anime to watch or song to

Jimmy 9 Jun 11, 2022
A command-line tool for re-packaging an epub that has been unzipped. Can also be used as a library.

?? zaino A command-line tool for re-packaging an epub that has been unzipped. Can also be used as a library. Installation To use zaino as a library, a

Zachary Golba 3 Aug 17, 2023
Brutally simple command line app for jotting things down

jot Brutally simple command line app for jotting things down. About jot lets you get things down before you forget, without fiddling folders, naming,

Alexander Alexandrov 1 Apr 8, 2022
The awesome-app Command Line Interface

Rust CLI to create Awesome Applications with Rust. More info at awesomeapp.org Install > cargo install awesome-app Create your first app: # Create you

RUST-AWESOME-APP 41 Jan 4, 2023
Save image from your clipboard 📋 as an image file directly from your command line! 🔥

Clpy ?? Save copied image from clipboard as an image file directly from your command line! Note It works only on windows as of now. I'll be adding sup

Piyush Suthar 13 Nov 28, 2022
Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.

Deadliner Watch the YouTube video What's Deadliner? Deadliner is a cross-platform desktop application for setting deadline for a project and keeping t

Deadliner 34 Dec 16, 2022
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022