Skip to content

Commit

Permalink
Merge pull request #11 from dalelotts/develop
Browse files Browse the repository at this point in the history
feat(model-type): Able to store date in the model as a Date, moment,milliseconds, or custom format
  • Loading branch information
dalelotts committed Jan 25, 2016
2 parents 8eda862 + 7ea6347 commit d9bca20
Show file tree
Hide file tree
Showing 22 changed files with 1,429 additions and 355 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
build
coverage
lib-cov
bower_components
Expand Down
8 changes: 8 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"disallowDanglingUnderscores": { "allExcept": ["_$compile_", "_$rootScope_"] },
"disallowMultipleVarDecl": "strict",
"preset": "crockford",
"requireMultipleVarDecl": null,
"requireVarDeclFirst": null,
"validateIndentation": 2
}
90 changes: 90 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 2, // {int} Number of spaces to use for indentation
"latedef" : "nofunc", // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : true, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
"notypeof" : false, // true: Tolerate invalid typeof operator values
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : true, // Web Browser (window, document, etc)
"browserify" : false, // Browserify (node.js code in the browser)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : true, // Jasmine
"jquery" : false, // jQuery
"mocha" : true, // Mocha
"mootools" : false, // MooTools
"node" : false, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
"shelljs" : false, // ShellJS
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Custom Globals
"globals" : {
"angular" : true,
"moment" : true
}
}
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.gitignore
.idea
.jshintignore
.jshintrc
.travis.yml
angular-date-time-input.iml
bower_components
complexity
coverage
demo
Gruntfile.js
gulpfile.js
karma.conf.js
paths.js
test
30 changes: 17 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: none
node_js:
- "0.10"

branches:
except:
- gh-pages

- '5'
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
before_script:
- npm install -g bower grunt-cli
- bower install

script: "grunt --verbose"
- npm prune
script:
- npm run test
after_success:
- npm run semantic-release
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
52 changes: 11 additions & 41 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,22 @@
/*globals module, require, process */

/*globals module, require */
/*jslint vars:true */
module.exports = function (grunt) {
'use strict';

// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

// Default task.
grunt.registerTask('default', ['jshint', 'karma', 'coverage']);

var testConfig = function (configFile, customOptions) {
var options = { configFile: configFile, keepalive: true };
var travisOptions = process.env.TRAVIS && { browsers: ['Firefox'], reporters: 'dots' };
return grunt.util._.extend(options, customOptions, travisOptions);
};

// Project configuration.
grunt.initConfig({
coverage: {
options: {
thresholds: {
'statements': 100,
'branches': 90,
'lines': 100,
'functions': 100
},
dir: 'coverage',
root: ''
}
},
karma: {
unit: {
options: testConfig('karma.conf.js')
}
},
jshint: {
files: ['src/*.js', 'test/**/*.js'],
bump: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true,
globals: {}
files: ['package.json', 'bower.json', 'README.md', 'src/js/*.js'],
updateConfigs: [],
commit: false,
createTag: false,
push: false,
globalReplace: false
}
}
});
};
};
131 changes: 110 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,36 @@ Native AngularJS directive that allows user input of a date/time value. Valid da
#Dependencies

Requires:
* AngularJS 1.1.3 or higher (Not tested with 1.0.x)
* AngularJS 1.4.x or higher
* MomentJS 2.1.x or higher

#Testing
We use karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:

```
npm install -g grunt-cli
npm install bower grunt
npm install -g gulp
npm install
npm test
```

The karma task will try to open Chrome as a browser in which to run the tests. Make sure this is available or change the configuration in test\test.config.js

#Usage
We use bower for dependency management. Add
We use npm for dependency management. Add the following to your package

```json
dependencies: {
"angular-date-time-input": "latest"
}
```shell
npm install angular-date-time-input --save
```

To your bower.json file. Then run

```html
bower install
```

This will copy the angular-date-time-input files into your components folder, along with its dependencies.
This will copy the angular-date-time-input files into your node_modules folder, along with its dependencies.

Load the script files in your application:
```html
<script type="text/javascript" src="components/moment/moment.js"></script>
<script type="text/javascript" src="components/angular/angular.js"></script>
<script type="text/javascript" src="components/angular-date-time-input/src/js/dateTimeInput.js"></script>
<script type="text/javascript" src="node_modules/moment/moment.js"></script>
<script type="text/javascript" src="node_modules/angular/angular.js"></script>
<script type="text/javascript" src="node_modules/angular-date-time-input/src/js/dateTimeInput.js"></script>
```

Add the date module as a dependency to your application module:
Add this module as a dependency to your application module:

```html
var myAppModule = angular.module('MyApp', ['ui.dateTimeInput'])
Expand All @@ -59,4 +51,101 @@ Apply the directive to your form elements:

## Options

The value of the date-time-input attribute must be a valid format string. See MomentJS documentation for valid formats.
The value of the date-time-input attribute is the format the date values will be displayed.

Nota bene: The value saved in the model is, by default, a JavaScript ```Date``` object, not a string.
This can result in differences between what is seen in the model and what is displayed.

### date-time-input

This option controls the way the date is displayed in the view, not the model.

```html
<input data-date-time-input="YYYY-MMM-DD" />
```
See MomentJS documentation for valid formats.

### date-formats

This option defines additional input formats that will be accepted.

```html
<input ... data-date-formats="['YYYY-MMM-DD']" />
```

Nota bene: Parsing multiple formats is considerably slower than parsing a single format.
If you can avoid it, it is much faster to parse a single format.

See [MomentJS documentation] (http://momentjs.com/docs/#/parsing/string-formats) for more information.

### date-parse-strict

This option enables/disables strict parsing of the input formats.

```html
<input ... data-date-parse-strict="false" />
```

### model-type

```html
<input ... data-model-type="Date | moment | milliseconds | [custom format]" />
```

Default: ```'Date'```

Specifies the data type to use when storing the selected date in the model.

Accepts any string value, but the following values have special meaning (these values are case sensitive) :
* ```'Date'``` stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model
* ```'moment'``` stores a moment instance in the model. Accepts the same initial values as ```Date```
* ```'milliseconds'``` store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date```

Any other value is considered a custom format string.

##Contributing

See [Contributing] (contributing.md) document

## License

angular-date-time-input is released under the MIT license and is copyright 2016 Knight Rider Consulting, Inc.. Boiled down to smaller chunks, it can be described with the following conditions.

## It requires you to:

* Keep the license and copyright notice included in angular-date-time-input's CSS and JavaScript files when you use them in your works

## It permits you to:

* Freely download and use angular-date-time-input, in whole or in part, for personal, private, company internal, or commercial purposes
* Use angular-date-time-input in packages or distributions that you create
* Modify the source code
* Grant a sublicense to modify and distribute angular-date-time-input to third parties not included in the license

## It forbids you to:

* Hold the authors and license owners liable for damages as angular-date-time-input is provided without warranty
* Hold the creators or copyright holders of angular-date-time-input liable
* Redistribute any piece of angular-date-time-input without proper attribution
* Use any marks owned by Knight Rider Consulting, Inc. in any way that might state or imply that Knight Rider Consulting, Inc. endorses your distribution
* Use any marks owned by Knight Rider Consulting, Inc. in any way that might state or imply that you created the Knight Rider Consulting, Inc. software in question

## It does not require you to:

* Include the source of angular-date-time-input itself, or of any modifications you may have made to it, in any redistribution you may assemble that includes it
* Submit changes that you make to angular-date-time-input back to the angular-date-time-input project (though such feedback is encouraged)

The full angular-date-time-input license is located [in the project repository](https://github.com/dalelotts/angular-date-time-input/blob/master/LICENSE) for more information.


## Donating
Support this project and other work by Dale Lotts via [gittip][gittip-dalelotts].

[![Support via Gittip][gittip-badge]][gittip-dalelotts]

[gittip-badge]: https://rawgithub.com/twolfson/gittip-badge/master/dist/gittip.png
[gittip-dalelotts]: https://www.gittip.com/dalelotts/

[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE

Loading

0 comments on commit d9bca20

Please sign in to comment.