├── pretty-time ├── .gitattributes ├── pretty-time.plugin.zsh ├── .editorconfig ├── .github └── workflows │ └── main.yml ├── pretty-time.zsh ├── package.json ├── license └── readme.md /pretty-time: -------------------------------------------------------------------------------- 1 | pretty-time.zsh -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /pretty-time.plugin.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | autoload -Uz pretty-time 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - run: npm install 20 | - run: npm test 21 | -------------------------------------------------------------------------------- /pretty-time.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | if (( $# == 0 )); then 4 | echo 'Input required' 5 | return 1 6 | fi 7 | 8 | local human total_seconds=$1 9 | local days=$(( total_seconds / 60 / 60 / 24 )) 10 | local hours=$(( total_seconds / 60 / 60 % 24 )) 11 | local minutes=$(( total_seconds / 60 % 60 )) 12 | local seconds=$(( total_seconds % 60 )) 13 | 14 | (( days > 0 )) && human+="${days}d " 15 | (( hours > 0 )) && human+="${hours}h " 16 | (( minutes > 0 )) && human+="${minutes}m " 17 | human+="${seconds}s" 18 | 19 | echo "$human" 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pretty-time-zsh", 3 | "version": "1.0.1", 4 | "description": "Convert seconds to a human readable string: 165392 → 1d 21h 56m 32s", 5 | "license": "MIT", 6 | "repository": "sindresorhus/pretty-time-zsh", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "bin": { 13 | "pretty-time": "pretty-time.zsh" 14 | }, 15 | "engines": { 16 | "node": ">=0.10.0" 17 | }, 18 | "scripts": { 19 | "test": "zsh -c \"[[ \\\"$(./pretty-time.zsh 165392)\\\" == \\\"1d 21h 56m 32s\\\" ]]\"" 20 | }, 21 | "files": [ 22 | "pretty-time.zsh" 23 | ], 24 | "keywords": [ 25 | "zsh", 26 | "sh", 27 | "shell", 28 | "bash", 29 | "script", 30 | "time", 31 | "seconds", 32 | "sec", 33 | "pretty", 34 | "human", 35 | "humanize", 36 | "duration", 37 | "period", 38 | "range" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # pretty-time-zsh 2 | 3 | > Convert seconds to a human readable string: `165392` → `1d 21h 56m 32s` 4 | 5 | 6 | ## Install 7 | 8 | 9 | Install with npm or Antigen, clone this repo, or just download the [`pretty-time.zsh`](pretty-time.zsh) file. 10 | 11 | ### Install with npm 12 | 13 | ``` 14 | $ npm install pretty-time-zsh 15 | ``` 16 | 17 | ### Install with Antigen 18 | 19 | ``` 20 | $ antigen bundle sindresorhus/pretty-time-zsh 21 | ``` 22 | 23 | ### Install with Zgen 24 | 25 | Add `zgen load sindresorhus/pretty-time-zsh` to your `.zshrc` and run `zgen reset`. 26 | 27 | 28 | ## Usage 29 | 30 | ```sh 31 | $ date +%s 32 | 1407771536 33 | 34 | $ ./node_modules/pretty-time-zsh/pretty-time.zsh 165392 35 | 1d 21h 56m 32s 36 | 37 | # seconds since epoch - yesterday since epoch + 11111 seconds 38 | $ ./node_modules/pretty-time-zsh/pretty-time.zsh "$(date +%s) - $(date -v-1d +%s) + 11111" 39 | 1d 3h 5m 11s 40 | ``` 41 | 42 | 43 | ## CLI 44 | 45 | ``` 46 | $ npm install --global pretty-time-zsh 47 | ``` 48 | 49 | ``` 50 | $ pretty-time 165392 51 | 1d 21h 56m 32s 52 | ``` 53 | 54 | 55 | ## Related 56 | 57 | See [`pretty-ms`](https://github.com/sindresorhus/pretty-ms) for a JavaScript version that converts from milliseconds. 58 | 59 | 60 | ## License 61 | 62 | MIT © [Sindre Sorhus](https://sindresorhus.com) 63 | --------------------------------------------------------------------------------