· Homepage · Report Bug / Request Feature ·
npm install @compactjs/parse-time
<script src="https://unpkg.com/@compactjs/parse-time/dist/index.umd.js"></script>
import { parse, stringify } from '@compactjs/parse-time';
// parse a time string to a number
parse('13:30'); // => 13.5
parse('13:19:48'); // => 13.33
// stringify a number to a time string
stringify(13.33); // => 13:19:48
// formating options:
stringify(13.33, 'hh'); // => 13
stringify(13.33, 'hh:mm'); // => 13:19
stringify(13.33, 'hh:mm:ss'); // => 13:19:48
// it accepts numbers higher than 24
stringify(34.5); // => 34:30:00
// to limit to a range between 0 and 24 (or 0-12),
// I recommend to use https://github.com/CompactJS/limit
stringify(limit(34.5, 24)); // => 10:30:00
npm run test
👤 Timo Bechtel timo@bechtel.solutions
- Website: https://timobechtel.com
- Twitter: @TimoBechtel
- GitHub: @TimoBechtel
Contributions, issues and feature requests are welcome!
- Check issues
- Fork the Project
- Create your Feature Branch (
git checkout -b feat/AmazingFeature
) - Test your changes
npm run test
- Commit your Changes (
git commit -m 'feat: add amazingFeature'
) - Push to the Branch (
git push origin feat/AmazingFeature
) - Open a Pull Request
This project uses semantic-release for automated release versions. So commits in this project follow the Conventional Commits guidelines. I recommend using commitizen for automated commit messages.
Give a ⭐️ if this project helped you!
Distributed under the MIT License.
This README was generated with ❤️ by readme-md-generator