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

angular-date-string-input

v1.1.0

Published

angular-datetime ================ This module includes a datetime directive and a parser service.

Downloads

1

Readme

angular-datetime

This module includes a datetime directive and a parser service.

Features

  • This module includes:
    • A directive adding type=datetime behavior to input[text]:
      • Use date object as modelValue.
      • Use arrow keys to move on different part of datestring.
      • Use arrow keys to increase/decrease value.
      • Typeahead. Ex. "se" -> "September".
    • A parser, which can parse date string into date object with defined format.
    • A formatter, which can convert date object into date string without Angular builtin date filter.
  • Support IE8.

Date string format

Apart from the formats provided officially, angular-datetime support some new tokens:

  • ZZ - represent timezone with colon (e.g. +08:00)

Demo

Install

Bower:

bower install angular-datetime --save

npm:

npm install angular-datetime-input --save

Usage examples

datetime service

// Setup dependency
angular.module("myApp", ["datetime"]);

// Use datetime parser
angular.controller("myController", function(datetime){
	// Create a parser
	var parser = datetime("yyyy-MM-dd");

	// Set to current date
	parser.setDate(new Date);
	parser.getText();	// -> "2015-01-30"

	// Parse a date string
	parser.parse("2015-01-30");
	parser.getDate();	// -> DateTime object
	
	// Set working timezone. Changing timezone will not affect date object but
	// date string (i.e. parser.getText()).
	parser.setTimezone("+0800");

	// Other properties
	parser.format;	// -> "yyyy-MM-dd"

	// Catch the parsing error
	try {
		parser.parse("2015-123-456");
	} catch (err) {
		console.log(err);	// -> {code: "...", message: "...", ...}
	}
});

datetime directive

Check demo page for live example.

<input type="text" datetime="yyyy-MM-dd" ng-model="myDate">
<input type="text" datetime="yyyy-MM-dd" ng-model="myDate" required>
<input type="text" datetime="yyyy-MM-dd" ng-model="myDate" datetime-utc>
<input type="text" datetime="yyyy-MM-dd" ng-model="myDate" min="Jan 1, 1990" max="Dec 31, 2050">
<input type="text" datetime="yyyy-MM-dd" ng-model="myDate" datetime-model="yyyy-MM-ddTHH:mm:ss">
<input type="text" datetime="yyyy-MM-dd" ng-model="myDate" default="Jan 1, 2000">
<input type="text" datetime="dd.MM.yyyy" ng-model="myDate" datetime-separator=",">

Parsing errors

  • TEXT_MISMATCH
  • NUMBER_MISMATCH
  • NUMBER_TOOSHORT
  • NUMBER_TOOSMALL
  • LEADING_ZERO
  • SELECT_MISMATCH
  • SELECT_INCOMPLETE
  • REGEX_MISMATCH
  • TEXT_TOOLONG
  • INCONSISTENT_INPUT

Known issues

  • 2 digit year 'yy' is ambiguous when converting datestring back to date object (Ex. 14 -> 2014, 1914, ...). You should avoid it.

Todos

  • Errors throwed by angular-datetime should have its own type.
  • Put some error handler into factory?
  • Day node should give different proper values depends on month when NUMBER_TOOLARGE.

Changelog

  • 4.1.0 (Oct 5, 2016)
    • Refactor.
    • Fix day priority bug.
    • Add parser.isEmpty. Fix required issue.
  • 4.0.0 (Sep 1, 2016)
    • Change how parser work. It can represent "undefined" node now.
    • Use tab key to navigate between different parts.
  • 3.2.2 (Jun 30, 2016)
    • Return false if there is no ngModel.
  • 3.2.1 (Jun 18, 2016)
    • Fix a bug that empty min, max cause invalid date.
  • 3.2.0 (May 17, 2016)
    • Support dynamic datetime-utc. #29
  • 3.1.1 (Apr 17, 2016)
    • Deploy to npmjs/angular-datetime-input.
    • Drop grunt.
  • 3.1.0
    • Jump on the next segment on pressing next separator key. (#26)
    • Add datetime-separator option.
    • Now it will try to fix NUMBER_TOOSHORT error when pressing left/right/separator key.
  • 3.0.1 (Apr 9, 2016)
    • Fix validator and datetime-model bug. #27
  • 3.0.0 (Apr 1, 2016)
    • Add token ZZ. #24
    • Fix datetime-utc issue. #21
    • Add parser.setTimezone. #22
    • Use PhantomJS for testing.
    • Change Angular dependency to ^1.2.0.
    • Fix date overflow bug.
  • 2.2.1 (Mar 31, 2016)
    • Fix reference error with "Z" token. See #20
  • 2.2.0 (Feb 23, 2016)
    • Add new error type "LEADING_ZERO", "NUMBER_TOOSMALL".
    • Use the behavior introduced in #18.
    • Add default attribute.
  • 2.1.0 (Jan 12, 2016)
    • Add datetime-utc option.
  • 2.0.1 (Jan 1, 2016)
    • Add MIT License
  • 2.0
    • Add min, max, datetime-model directive.
    • Support $validators in angular 1.3.x.
    • Update Eslint to 1.x.
    • Fix timezone token Z.
  • 1.0
    • Added Karma test.
    • Changed source structure.
    • Now you can chain parser's methods.
    • Parsing error won't mess up modelValue anymore.