datemath-cli
v1.6.3
Published
A beautiful CLI for date calculations in natural language
Maintainers
Readme
📅 DateMath CLI
A beautiful command-line tool for date calculations in natural language. Calculate days between dates, add/subtract time periods, and get human-readable date information.
✨ Features
- 🎨 Beautiful gradient ASCII art welcome screen
- 📊 Calculate days/weeks/months/years between dates
- ➕ Add or subtract time periods from dates
- 🗓️ Display dates in human-readable format
- 💬 Interactive calculator mode
- ⚡ Fast and lightweight
- 🎯 Type-safe TypeScript implementation
- ✅ Comprehensive test coverage
🚀 Installation
Global Installation (Recommended)
npm install -g datemath-cliLocal Development
npm install
npm run devUse with npx (No Installation)
npx datemath-cli <command>📖 Usage
Quick Start
Run without any commands to launch the interactive calculator:
npx datemath-cli
# or if installed globally
datemathThis will launch the interactive calculator mode where you can choose operations and enter dates step-by-step.
Show Today's Date
datemath todayOutput:
📅 Today is:
Friday, October 17, 2025
ISO format: 2025-10-17Calculate Days Since a Date
datemath since 2025-01-01Output:
📊 Time since Wednesday, January 1, 2025:
289 daysWith verbose output:
datemath since 2025-01-01 -vOutput:
📊 Time since Wednesday, January 1, 2025:
289 days
= 41 weeks
= 9 months, 19 daysCalculate Days Until a Date
datemath to 2025-12-25Output:
📊 Time until Thursday, December 25, 2025:
69 daysAlias:
datemath until 2025-12-25Calculate Time Between Two Dates
datemath between 2025-01-01 2025-10-17Output:
📊 Time between Wednesday, January 1, 2025 and Friday, October 17, 2025:
289 daysWith specific unit:
datemath between 2025-01-01 2025-10-17 --unit weeksOutput:
41 weeksShow all units:
datemath between 2025-01-01 2025-10-17 -vOutput:
📊 Time between Wednesday, January 1, 2025 and Friday, October 17, 2025:
289 days
41 weeks
9 months
0 years
9 months, 19 daysAdd Time to a Date
datemath add 2025-10-17 30 days
datemath add 2025-10-17 5 weeks
datemath add 2025-10-17 2 months
datemath add 2025-10-17 1 yearOutput:
📊 Friday, October 17, 2025 + 30 days:
Saturday, November 16, 2025
ISO format: 2025-11-16Subtract Time from a Date
datemath subtract 2025-10-17 30 days
datemath sub 2025-10-17 5 weeksOutput:
📊 Friday, October 17, 2025 - 30 days:
Thursday, September 17, 2025
ISO format: 2025-09-17Interactive Calculator Mode
datemath calcThis launches an interactive prompt where you can:
- Choose the type of calculation
- Enter dates step-by-step
- Get instant results with beautiful formatting
🎯 Command Reference
| Command | Description | Example |
|---------|-------------|---------|
| today | Show today's date | datemath today |
| since <date> | Days since a date | datemath since 2025-01-01 |
| to <date> | Days until a date | datemath to 2025-12-25 |
| until <date> | Alias for to | datemath until 2025-12-25 |
| between <date1> <date2> | Time between dates | datemath between 2025-01-01 2025-10-17 |
| add <date> <amount> <unit> | Add time to date | datemath add 2025-01-01 30 days |
| subtract <date> <amount> <unit> | Subtract time from date | datemath sub 2025-01-01 30 days |
| calc | Interactive calculator | datemath calc |
Options
-v, --verbose- Show detailed breakdown (forsince,to,between)-u, --unit <unit>- Specify unit: days, weeks, months, years (forbetween)-h, --help- Show help-V, --version- Show version
Date Format
All dates must be in ISO 8601 format: YYYY-MM-DD
Examples:
2025-10-17✅2025-01-01✅10/17/2025❌17-10-2025❌
Time Units
Supported units for add/subtract commands:
dayordaysweekorweeksmonthormonthsyearoryears
🛠️ Development
Setup
# Clone the repository
git clone https://github.com/ahmadawais/datemath-cli.git
cd datemath-cli
# Install dependencies
npm install
# Run in development mode
npm run devAvailable Scripts
npm run dev # Run in development mode with watch
npm run build # Build for production
npm test # Run tests once
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run typecheck # Type check without emitting
npm run lint # Lint code
npm run format # Format code with PrettierProject Structure
datemath-cli/
├── src/
│ ├── index.ts # Main CLI entry point
│ └── index.test.ts # Test suite
├── dist/ # Compiled output (generated)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── tsup.config.ts # Build configuration
├── vitest.config.ts # Test configuration
└── README.md # This fileRunning Tests
# Run all tests
npm test
# Watch mode (re-runs on file changes)
npm run test:watch
# Coverage report
npm run test:coverageBuilding
# Build the project
npm run build
# Test the built version locally
npm link
datemath today📦 Publishing
# Update version
npm version patch # or minor, or major
# Build
npm run build
# Publish to npm
npm publish
# Push tags to git
git push --tags🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
👨💻 Author
Ahmad Awais - Website · GitHub · Twitter
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with Commander.js
- Beautiful prompts by @clack/prompts
- Styled with Chalk and gradient-string
📧 Support
If you have any questions or run into issues, please open an issue on GitHub.
Made with 💜 by Ahmad Awais
