Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-time-to-ms

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-time-to-ms - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

sequence.js

5

example/basic.js
var parseTime = require('../')
var parseTimes = require('../sequence')
console.log(parseTime('8:00'))
console.log(parseTime('08:00'))
var timeRange = parseTime.s('18:00', '23:30')
var timeRange = parseTimes('18:00', '23:30')
console.log(timeRange)

8

example/date.js
var parseTime = require('../')
var day = new Date(2017, 0, 1)
var date = new Date(2017, 0, 1)
console.log(day.toString())
console.log(date.toString(), 'initial date')
var time = parseTime('15:00')
var datetime = new Date(+day + time)
var datetime = new Date(+date + time)
console.log(datetime.toString())
console.log(datetime.toString(), 'added "15:00" to Date object' )
module.exports = parseTime
module.exports.s = seq
var multiplier = [60, 60, 1000] // hh, mm, ss
function seq (...times) {
return times.map(parseTime)
}
function parseTime (time) {

@@ -11,0 +6,0 @@ if (typeof time !== 'string') {

{
"name": "parse-time-to-ms",
"version": "0.1.0",
"version": "1.0.0",
"description": "Ultralight module to parse a time string into milliseconds.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,3 +10,3 @@ # parse-time-to-ms

hh:mm:ss.sss or hhmmss.sss
hh:mm:ss or hhmmss
hh:mm:ss or hhmmss
hh:mm or hhmm

@@ -20,3 +20,5 @@ hh

Invalid format: '2:35' (need a trailing 0)
# example

@@ -26,8 +28,9 @@

var parseTime = require('parse-time-to-ms')
var parseTimes = require('parse-time-to-ms/sequence')
parseTime('8:00')
console.log(parseTime('08:00'))
// => 28800000
var timeRange = parseTime.s('18:00', '23:30')
var timeRange = parseTimes('18:00', '23:30')

@@ -44,5 +47,5 @@ console.log(timeRange)

var day = new Date(2017, 0, 1)
var date = new Date(2017, 0, 1)
var time = parseTime('15:00')
var datetime = new Date(+day + time)
var datetime = new Date(+date + time)

@@ -77,3 +80,3 @@ console.log(datetime.toString())

`parse-time-to-ms` use ES6 Rest Parameters.
`parse-time-to-ms/sequence` use ES6 Rest Parameters.

@@ -97,1 +100,2 @@

- https://github.com/unshiftio/millisecond Similar purpose, but from natural language.
- https://github.com/zeit/ms idem
var parseTime = require('../')
var parseTimes = require('../sequence.js')
var test = require('tape')

@@ -46,4 +47,4 @@

test('sequence', function (t) {
var sequenceA = parseTime.s('00:30', '02:25:30', '12:34:10.349')
var sequenceB = parseTime.s('00:30', '02:25:30', '12:34:10.349')
var sequenceA = parseTimes('00:30', '02:25:30', '12:34:10.349')
var sequenceB = parseTimes(['00:30', '02:25:30', '12:34:10.349'])
var expectedMs = [

@@ -55,4 +56,4 @@ new Date(2017, 0, 1, 0, 30, 0, 0) - baseTime,

t.deepEqual(sequenceA, expectedMs)
t.deepEqual(sequenceB, expectedMs)
t.deepEqual(sequenceA, expectedMs, 'able to parse a list of arguments')
t.deepEqual(sequenceB, expectedMs, 'able to parse an array')
t.end()

@@ -59,0 +60,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc