Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error for invalid date format #26

Merged
merged 14 commits into from
Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ FieldVal-JS

The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports.

[![MinoHubs](https://www.minohubs.com/badge/fieldval/support.svg)](https://www.minohubs.com/hub/fieldval)

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/FieldVal/fieldval-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Documentation and Examples
=============

Expand All @@ -17,4 +21,4 @@ This project uses [gulp.js](http://gulpjs.com/) to build and [mocha](http://visi
npm install
gulp js
mocha test/test
```
```
4 changes: 4 additions & 0 deletions src/DateVal.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ var DateVal = (function(){
date_with_format_array: function(date, format_array){
//Takes a Javascript Date object

if (!Array.isArray(format_array)) {
throw new Error('Not a valid date format');
}

var date_string = "";

for(var i = 0; i < format_array.length; i++){
Expand Down
13 changes: 13 additions & 0 deletions test/DateVal_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ describe('DateVal', function() {

assert.equal(null, my_validator.end());
})

it('should throw an exception for invalid date format', function() {

var my_validator = new FieldVal({
"my_format": "yyy-MM-dd hh:mm:ss"
})

var format_array = my_validator.get("my_format", BasicVal.string(true), BasicVal.date_format());

var test_date = new Date(Date.UTC(2014, 08, 10, 16, 05, 38));//'Wed Sep 10 2014 16:05:38 GMT+0100 (BST)');

assert.throws(function() { DateVal.date_with_format_array(test_date, format_array); }, Error);
})
})

describe('pad_to_valid()', function() {
Expand Down