2.2.13 • Published 5 months ago

input-duration v2.2.13

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

npm bundle size Contributors Forks Stargazers Issues MIT License RepoSize Build StatusDIY Build StatusDIY

'Time Only' means that this control is for time as a unit, or a duration, like for count down timers. Not for time of day nor date on a calendar, so no unwanted AM/PM conversions on Safari, no unwanted date-time selectors. Just time up to 999 hrs and down to 1 millisecond.

OS(mobile)BrowserOS(laptop)Browser
AndroidChromeWindows 10, 11Chrome, Edge
iOSSafari, ChromeOsXSafari, Chrome

About The Project

Time inputs are updated by browsers in unwanted ways! Safari on desktop adds AM/PM if the user is in the USA and on mobile the cool scroll time selector does not allow fractions of a second. The best html5 option doesn't cut it, sadly, so input-duration was designed and buit for a consistant UX no matter the browser, OS, or location settings.

*note input-duration needs closing tag!

The objective is a minimised javascript plugin that reproduces the behaviour of the input type=time on Chrome. This way at least two of the major browsers are supported, Safari and Chrome, on desktop and mobile operating systems.

Does this loose any functionality? No! document.querySelector('#bob').value has a getter and setter! So values can be set and retrieved by ID or attribute in HTML.

Yes! It seems CRAZY in 2022 that there is not a native 'time only' input for HTML. What I mean is there is no user input control for time rendered independantly of date or time of day. Yea, crazy, but now input-duration is a javascript plugin that creates a UX input control for a value of time simply as hours, minutes, seconds --only! Ever thought, why is it difficult to 'code' a countdown timer? Why can't it be done with one control? Just look at google's timer and other coundown timers! All use multiple inputs, usually designed for integers.

The very worst is Safari on desktop and mobile, which undermine any input type=time coding efforts and update the input based on OS settings! Shouldn't a user be able to 'scientifically' specify a period of time with one control? Maybe it's just me, but the chrome / google timer is 14 separate elements ... those guys must be paid by the hour. The closest HTML5 input type- time when configured with UX for hours to millisecs is very finicky and is rendered differently on Chrome than Safari. Mobile is different from laptop ... so I've simplified that!

There were a few plugins that remediated the lack of continuity, but even those controls treated time as a date (ex 24hr max). So it seems the current state is the most relable UX is multi input type number. The worst example is the Google countdown timer. That way is wrong because time is a basic unit that should be separate from calendar complexities. That got me thinking, why isn't there an input control for it implemented across browsers?? I needed one, so coded input-duration.

Here's why:

  • Time is hours minutes and seconds (and millisecs) and needn't be associated with part of a day or a date
  • The date association breaks UX and is varied with browser implementation
  • I found no other crossbrowser solution
  • I thought this would be a great open source project
  • End use of number inputs (standard hack) for use with time

Of course, this is functional but in it's infancy. Maybe, with some contribution this is a project that can inspire change to the HTML spec.

Feel free to vote for WhatWG inclusion of a into the HTML spec! (link comming soon)

Built With

input-duration is a module and works with webpack. Any add-ons/plugins used in dev are in the acknowledgements section.

Getting Started

There are no pre-requisites for using input-duration if you're not compiling/ packaging you javascript. If you are packaging:

Prerequisites

This is an example of how to get started with npm and webpack, other frameworks should work too.

  • npm & webpack
    npm install npm@latest -g
    npm init -y
    npm install webpack webpack-cli --save-dev

Installation

With packaging: This template doesn't rely on any external dependencies or services.

  1. Install from NPM
     npm i input-duration
  2. import input-duration in javascript

    import id from 'input-duration';
  
Without packaging:

1. Add script:
 ```bash

<script type="module">

import id from 'https://cdn.jsdelivr.net/npm/input-duration/+esm'
        
 </script>
  

Usage

input-duration requires a <input-duration> element . There's no more HTML than that, but don't forget the closing tag. Native Input elements don't have them!

<input-duration id='bob'></input-duration>

If you would like to get or set values or to disable input-duration elemet, javascipt can do that:

document.querySelector('#bob').value = '44:04:04.444'

and

document.querySelector('#bob').disable()

so the inputs are modified.

For more documentation, please refer to the jscocs on input-duration Docs

Roadmap

  • Emperically determine behaviour of Input (time) on Chrome
  • Reverse engineer input behaviour (arrows, digits, 0 addition, etc.)
  • Cross browser/ cross os manual tests
  • Get Chrome behavioural specification for
  • Add end to end multi-browser, multi-os Selinium tests
  • Update demo page (either PM.com or JSfiddle type)
  • Multi-language documentation (Google translate of this page?)
    • Chinese
    • Spanish
  • min and max values (sorry for the moment you'll have to do those yourself in js)

See the open issues for a full list of proposed features (and known issues).

Teststatus

TestStatusDIY TestStatusDIY TestStatusDIY TestStatusDIY TestStatusDIY TestStatusDIY

Tests & Live Status

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Stephan Luis - stephan@learnsense.org

Project Link: https://github.com/StephanLuis/input-duration

Acknowledgments

Resources I've found helpful and would like to give credit to:

2.2.26

5 months ago

2.2.27

5 months ago

2.2.25

5 months ago

2.2.18

5 months ago

2.2.19

5 months ago

2.2.24

5 months ago

2.2.22

5 months ago

2.2.23

5 months ago

2.2.20

5 months ago

2.2.21

5 months ago

2.2.17

5 months ago

2.2.15

5 months ago

2.2.16

5 months ago

2.2.13

5 months ago

2.2.14

5 months ago

2.2.11

5 months ago

2.2.12

5 months ago

2.2.10

5 months ago

2.2.9

5 months ago

2.2.7

5 months ago

2.2.1

7 months ago

2.2.3

7 months ago

2.2.2

7 months ago

2.2.5

7 months ago

2.2.6

7 months ago

2.1.1

10 months ago

2.1.0

10 months ago

2.0.12

10 months ago

2.0.11

10 months ago