https://github.com/gajus/extract-time
Extracts time from an arbitrary text input.
https://github.com/gajus/extract-time
moment parse time
Last synced: 3 months ago
JSON representation
Extracts time from an arbitrary text input.
- Host: GitHub
- URL: https://github.com/gajus/extract-time
- Owner: gajus
- License: other
- Created: 2018-12-30T12:10:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-01T03:22:39.000Z (over 5 years ago)
- Last Synced: 2025-06-19T05:18:06.892Z (4 months ago)
- Topics: moment, parse, time
- Language: JavaScript
- Size: 41 KB
- Stars: 18
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/gajus/extract-time)
[](https://coveralls.io/github/gajus/extract-time)
[](https://www.npmjs.org/package/extract-time)
[](https://github.com/gajus/canonical)
[](https://twitter.com/kuizinas)Extracts time from an arbitrary text input.
* [extract-time ⏰](#extract-time)
* [Features](#extract-time-features)
* [Usage](#extract-time-usage)
* [Signature](#extract-time-signature)
* [Related projects](#extract-time-related-projects)* Deterministic and unambiguous time parsing.
```js
import extractTime from 'extract-time';extractTime('extracts time from anywhere within the input 14:00');
// [{time: '14:00'}]extractTime('extracts multiple times located anywhere within the input: 16:00, 18:00');
// [{time: '16:00'}, {time: '18:00'}]extractTime('distinguish between the civilian 1:30 PM ...');
// [{time: '13:30'}]extractTime('... and military time formats 13:30');
// [{time: '13:30'}]extractTime('resolves ambiguous times using the provided time notation bias 1:30', 12);
// [{time: '13:30'}]```
```js
/**
* Indicates if time format is 12-hour or 24-hour clock notation.
*/
export type TimeNotationType = 12 | 24;/**
* @property time 24-hour military time.
*/
type TimeMatchType = {|
+time: string
|};/**
* @param subject Arbitrary text input.
*/
type extractTime = (
subject: string,
timeNotation: TimeNotationType,
) => $ReadOnlyArray;```
* [`extract-date`](https://github.com/gajus/extract-date) – Extracts date from an arbitrary text input.
* [`extract-price`](https://github.com/gajus/extract-price) – Extracts price from an arbitrary text input.