npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

half-past

v0.0.3

Published

natural-language date-parsing in javascript

Downloads

14

Readme

work-in-progress

rule-based interpreter for natural-language date-forms.

an opinionated-but-configurable mash-up of spacetime and compromise

you've been warned!

IF YOU DARE:

npm install half-past

Usage:

var nlp = require('compromise')
var halfPast = require('half-past')
//apply plugin
nlp.plugin(halfPast)

let context = {
  // what 'today', or 'now' is
  now: '2018-09-10T17:28:32.140Z', // defaults to Date.now()
  // our assumed timezone, unless given
  timezone: 'Canada/Eastern',
  // set our calendar assumptions
  days: {
    start: '8:00am', // colloquial start/end of a day
    end: '6:00pm',
  },
  weeks: {
    start: 'monday', // some disagree.
    end: 'friday'
  },
  casual:{ // amount of time returned in 'after June 5th', etc.
    weeks:2
  },
  holidays: {
    'may day': '2018-06-01', // throws-away year info
  },
  // seasons: [ // defaults to northern-hemisphere (sorry!)
  //   '2018-03-01', //spring
  //   '2019-01-01', //summer
  //   '2019-04-01', //winter
  //   '2019-07-01', //fall
  // ],
  // quarters: [
  //   '2018-01-01', //q1
  //   '2019-04-01', //q2
  //   '2019-07-01', //q3
  //   '2019-09-01', //q4
  // ],
  // semesters: [ // https://en.wikipedia.org/wiki/Academic_term
  //   '2018-09-01',
  //   '2019-01-01',
  //   '2019-04-01',
  // ],
}

let result=halfPast(nlp('june 1st'), context)
/*
[{
  start:SpacetimeObject, //you can call .format('iso') or anything you want
  end:SpacetimeObject,
  precision:'day',
  interval:{
    unit:'month',
    amount:3
  },
}]
*/
console.log(result[0].start.format('iso'))
// 2018-06-01T11:18:58.040-04:00

How it works

half-past understands natural language date-forms using the following classification:

Single dates:

[two days after]  [the end of]    [next]    [thursday]  [at 2pm]   [EST]
   'shift'          'section'    'relative'    'unit'    'time'   'timezone'

[6 hours before]  [the start of]  [this]  [quarter]

Combined dates

these single-dates can be interpreted as two dates, that share information

between [date] and [date]
[date] to [date]
before [date]
after [date]
in [date]

See also

Other languages

There are also some excellent commercial services for date-parsing, which we've omitted here.

MIT