builtnoble / duration-fieldtype
A Statamic fieldtype for storing and displaying time durations as millisecond-precision integers, entered via a masked hh:mm input.
Package info
github.com/builtnoble/duration-fieldtype
Language:JavaScript
pkg:composer/builtnoble/duration-fieldtype
Requires
- php: ^8.3
- statamic/cms: ^6.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pint: ^1.30
- orchestra/testbench: ^10.8
- pestphp/pest: ^4.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-09 00:37:25 UTC
README
A Statamic fieldtype for storing and displaying time durations. Values are saved as integers in milliseconds, entered via a masked
hh:mminput in the Control Panel, and output in Antlers templates as either plainhh:mmor an optional human-readable string.
Features
- Millisecond integer storage — values are saved as raw integers (e.g.
5400000for 1 hour 30 minutes), keeping arithmetic and sorting predictable - Masked
hh:mminput — the Control Panel field renders a masked input that automatically formats digits as hours and minutes, capped at99:59by default - Configurable max hours — cap the field below 99 hours (e.g.
8for a workday tracker) via the field's "Max Hours" setting; minutes always range00–59 - Keyboard stepping — pressing
↑or↓while the field is focused increments or decrements whichever single digit the cursor sits immediately after - Paste support — pasting any text extracts its digits and replaces the field's value, clamped to the field's bounds
- Truncation to minute — partial minutes are discarded on load; sub-minute precision is not stored or displayed
- Antlers ready — augmented values default to plain
hh:mm(matching the Control Panel display) unless all four unit labels are configured, in which case they become a human-readable string (e.g.01 hr 30 mins, or1 hr 30 minswith leading zeros stripped) with the minutes segment omitted entirely when zero - Localizable labels — optionally configure
hr/hrs/min/mins-style labels per field, so a site can translate them without the addon needing to bundle every language - Null-safe — null values display as
00:00in the CP and00 minsin templates
Requirements
- PHP 8.3+
- Statamic 6.0+
How to Install
Install the addon via Composer:
composer require builtnoble/duration-fieldtype
Then add the fieldtype to any blueprint in the Control Panel or directly in resources/blueprints/.
Documentation
See DOCUMENTATION.md for configuration options and a full explanation of how the fieldtype works internally.
Development
composer test # Pest (PHP) composer test:feature # Pest, feature-grouped only composer lint # Pint, check only composer analyse # PHPStan composer check # lint + analyse + test, all at once
See CONTRIBUTING.md for the full development setup and workflow.