프로젝트
GitHub에서 보기 parse-duration
jkroso/parse-duration
소개
사람이 읽을 수 있는 형식의 기간을 밀리초로 변환합니다.
기타 프로젝트측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalparse-duration 
Convert a human readable duration to ms.
Usage
import parse from 'parse-duration'
// parse different time units
let ns = parse('1ns') // => 1 / 1e6
let μs = parse('1μs') // => 1 / 1000
let ms = parse('1ms') // => 1
let s = parse('1s') // => ms * 1000
let m = parse('1m') // => s * 60
let h = parse('1h') // => m * 60
let d = parse('1d') // => h * 24
let w = parse('1w') // => d * 7
let mo = parse('1mo') // => y / 12
let y = parse('1y') // => d * 365.25
// compound expressions
parse('1hr 20mins') // => 1 * h + 20 * m
parse('1 hr 20 mins') // => 1 * h + 20 * m
// youtube format
parse('1h20m0s') // => 1 * h + 20 * m
// clock format, last segment is seconds
parse('1:30:00') // => 1 * h + 30 * m
parse('1:30') // => 1 * m + 30 * s
parse('1:30 h') // => 1 * h + 30 * m, units name the first segment
// comma seperated numbers
parse('27,681 ns') // => 27681 * ns
// noisy input
parse('duration: 1h:20min') // => 1 * h + 20 * m
// negatives
parse('-1hr 40mins') // => -1 * h - 40 * m
// exponents
parse('2e3s') // => 2000 * s
// custom output format
parse('1hr 20mins', 'm') // => 80
parse('1hr 20mins', 'MINS') // => 80, same matching rules as input units
// add units
parse.unit['μs'] = parse.unit.microsecond
parse('5μs') // => 0.005
Locales
Switch the default en locale to another language (see /locale).
import es from 'parse-duration/locale/es.js'
import parse from 'parse-duration'
parse.unit = es
parse('1 hora 20 minutos', 'm') // 80
For unit guessing in inputs such as 1h30, order numeric unit entries in custom locales from largest to smallest, keeping aliases next to their matching unit. Put new units that should be inferred at the matching position. Adding an alias for an existing unit to the built-in locale, as above, does not change unit guessing.
Safety
In sensitive APIs make sure input string is reasonably short (under 100 characters).
관련 프로젝트 살펴보기
불러오는 중…
