Code Monkey home page Code Monkey logo

pdd's Introduction

pdd

Latest release Availability PyPI Build Status License

Asciicast

pdd (Python3 Date Diff) is a tiny command line utility to calculate date and time difference. It can also be used as a timer. If no program arguments are specified it shows the current date, time and timezone.

pdd has been written with only one goal - simplicity. Users shouldn't have to memorize anything.

Table of Contents

Features

  • easy to use, minimal dependencies
  • calculate date and time difference
  • calculate diff from today and now
  • add, subtract duration (timeslice) to/from date (time)
  • countdown timer with command piggybacking
  • custom resolution stopwatch
  • non-verbose mode for background timers
  • show current date, time and timezone
  • follows ISO 8601

Installation

Dependencies

pdd requires Python 3.8 (or later) and the dateutil module.

To install dateutil on Ubuntu, run:

$ sudo apt-get install python3-dateutil

or, using pip3:

$ sudo pip3 install python-dateutil

From a package manager

Install pdd from your package manager. If the version available is dated try an alternative installation method.

Packaging status (expand)


Packaging status

Unlisted packagers:


PyPI (pip3 install pdd)
● Termux (pip3 install pdd)

Release packages

Packages for Arch Linux, CentOS, Debian, Fedora and Ubuntu are available with the latest stable release.

From source

If you have git installed, clone this repository. Otherwise download the latest latest stable release or development version (risky).

Install to default location (/usr/local):

$ sudo make install

To remove, run:

$ sudo make uninstall

PREFIX is supported, in case you want to install to a different location.

Running standalone

pdd is a standalone utility. From the containing directory, run:

$ chmod +x pdd
$ ./pdd

Usage

cmdline options

usage: pdd [-h] [-d yyyy mmm dd [yyyy mmm dd | y m d]]
           [-t hh:mm:ss [hh:mm:ss | h:m:s]] [--add] [--sub]
           [--day yyyy mmm dd] [-c hh:mm:ss] [-r command] [-s [resolution]] [-q] [-v]
           [keywords ...]

Tiny date, time difference calculator with timers.

positional arguments:
  keywords              diff/add/subtract from today or now

options:
  -h, --help            show this help message and exit
  -d yyyy mmm dd [yyyy mmm dd | y m d], --date yyyy mmm dd [yyyy mmm dd | y m d]
                        calculate date difference
  -t hh:mm:ss [hh:mm:ss | h:m:s], --time hh:mm:ss [hh:mm:ss | h:m:s]
                        calculate time difference
  --add                 add to date (/today) or time (/now)
  --sub                 subtract from date (/today) or time (/now)
  --day yyyy mmm dd     show day of the week on a date
  -c hh:mm:ss, --timer hh:mm:ss
                        start a countdown timer
  -r command, --run command
                        run command when countdown timer reaches 0
  -s [resolution], --stopwatch [resolution]
                        start a stopwatch [default resolution: 3 (ms)]
  -q, --quiet           quiet mode for background timer/stopwatch
  -v, --version         show program's version number and exit

Completion scripts are available for Bash, Fish and Zsh shells.

Operational notes

  • ISO 8601 format. Month can be specified as month number (e.g. Jan - 1, Dec - 12).
  • Time is in 24-hr format.
  • The absolute difference is shown. Argument order is ignored.
  • The end date is excluded in date difference calculations.
  • Hour, minute or second can be omitted. Partial inputs are recognized as mm:ss or ss.
  • The keybind to stop timers is Ctrl-C.

Examples

  1. Calculate diff from today:

    $ pdd 2014 Jan 15
    5y 2m 21d
    1906d
    
  2. Calculate diff from now:

    $ pdd 24:00:00
    15:24:03
    55443s
    
    $ pdd 0
    08:36:22
    30982s
    
  3. Calculate date diff:

    $ pdd -d 1983 jul 3 2014 1 15
    30y 6m 12d
    11154d
    
  4. Calculate time diff:

    $ pdd -t 45:50 6:17:33
    05:31:43
    19903s
    
  5. Show current date, time and timezone:

    $ pdd
    Fri 2019 Apr 5 08:37:25 IST
    
  6. Specify time with roll-over:

    $ pdd -t 5:80:75 6:17:33
    00:03:42
    222s
    
  7. Add a duration (3 years, 2 months, 1 day) to 28 Feb, 2000:

    $ pdd -d 2000 FEB 28 3 2 1 --add
    Tue 2003 Apr 29
    
  8. Add a timeslice (1 hour 2 mins 3 secs) to 23:45:37:

    $ pdd -t 23:45:37 1:2:3 --add
    1 day(s) later, 00:47:40
    89260s
    
  9. Add a duration (3 years, 2 months, 1 day) to today:

    $ pdd 3 2 1 --add
    Mon 2022 Jun 06
    
  10. Add a timeslice (1 hour 2 minutes 3 seconds) to now:

    $ pdd 1:2:3 --add
    09:41:26
    34886s
    
  11. Subtract a duration (1 day) from 1 Mar, 2000:

    $ pdd -d 2000 Mar 01 0 0 1 --sub
    Tue 2000 Feb 29
    
  12. Subtract a timeslice (1 sec) from midnight:

    $ pdd -t 00:00:00 0:0:1 --sub
    1 day(s) earlier, 23:59:59
    -1s
    
  13. Subtract a duration (3 years, 2 months, 1 day) from today:

    $ pdd 3 2 1 --sub
    Thu 2016 Feb 04
    
  14. Subtract a timeslice (1 hour 2 minutes 3 seconds) from now:

    $ pdd 1:2:3 --sub
    07:40:02
    27602s
    
  15. Show the day of the week on 15 Jan 2014:

    $ pdd --day 2014 Jan 15
    Wed
    
  16. Start a countdown timer or stopwatch in quiet mode in the background:

    $ pdd -qs &
    $ pdd -qc 3:0:0 &
    

    To see the final counter run fg and press Ctrl-C.

  17. Run a command when countdown timer reaches 0

    $ pdd -c 00:00:5 -r 'ps -aux'
    $ pdd -c 00:00:5 -r 'notify-send pdd "timer expired"'
    

Copyright

Copyright © 2017 Arun Prakash Jana

pdd's People

Contributors

bwagner avatar dmarcoux avatar freed-wu avatar jarun avatar jeremypress avatar maxice8 avatar mosrod avatar run-ze avatar santilococo avatar scarabeusiv avatar txgk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdd's Issues

pypi invitation

hi, i just realized you invited me on pypi for this project

unfortunately i have to decline it because i have less interest for this project.

pip install ppd fails for python 3.10.4 and 3.10.8 on macOS 12.6 (Monterey)

pip install ppd fails for python 3.10.4 and 3.10.8 on macOS 12.6 (Monterey) with FileNotFoundError: [Errno 2] No such file or directory: 'pdd'

Workaround: Downloading the zip-file and installing with pip install pdd-master.zip succeeds.

Transcript:

pip install pdd
Collecting pdd
  Using cached pdd-1.6.tar.gz (22 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/88/ycwg1tqn27q6xc2h7whfx8d00000gp/T/pip-install-3zwkde0k/pdd_39109a313a5d4095bced56f61a637d7d/setup.py", line 9, in <module>
          shutil.copyfile('pdd', 'pdd.py')
        File "/Users/.../.asdf/installs/python/3.10.8/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 254, in copyfile
          with open(src, 'rb') as fsrc:
      FileNotFoundError: [Errno 2] No such file or directory: 'pdd'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

diff default to today

Hi @jarun and thank you for all your delightful tools.

I often find myself looking for the number of days remaining from today to X.

Right now, I can get it as follow:

$ pdd -d 2020 Jul 5 $(date +"%Y %b %d")
0y 2m 26d
87d

But it would be simpler to just type:

$ pdd -d 2020 Jul 5
usage: pdd [-h] [-d yyyy mmm dd [yyyy mmm dd | y m d]] [-t hh:mm:ss [hh:mm:ss | h:m:s]] [--add] [--sub] [--day yyyy mmm dd] [-c hh:mm:ss] [-r command] [-s [resolution]] [-q] [keywords [keywords ...]]
pdd: error: argument -d: expected 6 arguments

Can you make it so that if only 3 arguments are given to pdd -d, the remaining 3 are auto-evaluated to today?

Use ISO 8601 format [YYYY MM DD] in dates

Though it's well documented, the utility should follow standards.

This would be done just before the next release so users of the current release are not confused.

python 3.8 problem

Update to python3.8 seems to have broken pdd


$ pdd
Traceback (most recent call last):
  File "/usr/local/bin/pdd", line 29, in <module>
    from dateutil.relativedelta import relativedelta
ModuleNotFoundError: No module named 'dateutil'
$ ln -s python3.7m.exe python3
$ pdd
Sun 2021 Jan 10 00:41:02 EST

Add MANIFEST.in

This file is needed to include the LICENSE and CHANGELOG files in the PyPI package.

[advice] Change shtab

I propose use some library like https://docs.iterative.ai/shtab to generate shell completion. Just

pdd --print-completion XXX

Maybe easier. One hard problem is shtab doesn't support generate shell completion for nargs > 1.
I advise change pdd -d yyyy mmm dd to pdd -d yyyy-mmm-dd to avoid this problem.

Advantage:

Disadvantage:

  • Break the compatibility

Customizable time/date diff output

Hi @jarun, thanks a ton for a very useful tool!

As I understand it, pdd (the command line tool) currently only outputs the time difference In the following format:

%02d:%02d:%02d
%ds

I was wondering if it would be possible to add an option to change that on run time.

Thanks a ton!

Can it "add" more than two timestamps?

First thanks for this very helpful tool,
i frequently need to determine the differences between two timestamps
and this tool really helps me!

about the --add option, can it work with more than two timestamps ?
e.g

pdd -t 00:01:00 00:02:00 00:03:00 --add

results:

00:03:00
180s
08:11:54
29514s

expected results:

00:06:00
360s

or if there another workflow/approach i will be grateful.

note: my plan is to add dozens of timestamps, not just three. thanks in advance

How to use the zsh_completion.py script ?

Hi,

I'm trying to update pdd (pdd-git) to V1.6 on the AUR but I'm struggling with the zsh completion.

For ddgr (which I also maintain on the AUR), the _ddgr file for zsh completion is already provided in the archive, but with pdd I have to generate the _pdd file myself during the packaging process by executing the zsh_completion.py, is that right ?

If that's so, I cannot seems to make it work... Here the result I get:
python zsh_completion.py

Traceback (most recent call last):
  File "/tmp/pdd/src/pdd/auto-completion/zsh/zsh_completion.py", line 121, in <module>
    parser = __import__(PACKAGE).get_parser()
ModuleNotFoundError: No module named 'pdd'

Unfortunately, I'm not good enough with python to find my way out.

Can you help me generating the zsh completion file ?
Thanks in advance !

BTW, thanks for your awesome works :)

new pypi release

Hi, is there any work needed to publish a new pypi release? (I'm running into the shutil.copy issue in setup.py from an outdated release)

btw, this project looks awesome

Windows support may be limited

FYI:

lib\python\python lib\pdd\pdd.py
Traceback (most recent call last):
File "lib\pdd\pdd.py", line 412, in
main()
File "lib\pdd\pdd.py", line 244, in main
args = parse_args()
File "lib\pdd\pdd.py", line 237, in parse_args
t.tm_hour, t.tm_min, t.tm_sec, t.tm_zone))
AttributeError: 'time.struct_time' object has no attribute 'tm_zone'

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.