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

Date: predate test; suggestion #49

Closed
arfa2 opened this issue Sep 19, 2016 · 1 comment
Closed

Date: predate test; suggestion #49

arfa2 opened this issue Sep 19, 2016 · 1 comment

Comments

@arfa2
Copy link

arfa2 commented Sep 19, 2016

I am not sure if this is useful? I wondered about you having a space for add-ons, or snippets - which is really what this is. I imagine different users create bits of code - that work for them - and could be useful for others. You could list - but not support or guarantee.
Anyhow...
This uses date format yyyy-mm-dd or,
yyyy-mm-dd hh:mm

messages = {
... as per,
mustPostDate : 'Depart <i>after</i> Arrival'
},

  Validator = {

    // postDate check; end date must be after start date
    postDate : function( tmp, self ) { 
            var startDate = self.form.querySelector('input[name="'+ tmp.arg +'"]').value;
        if (startDate.length>'0') { // startDate must be set
            // work on start date
        if (/ /g.test(startDate)) { // with time: "yyy-mm-dd HH:MM" - 24hr clock
            var startRaw = startDate.split(' ')[0].split('-');
            var timeRaw = startDate.split(' ')[1].split(':');
                var hours = timeRaw[0];
                var mins = timeRaw[1]; }
        else { var startRaw = startDate.split('-'); // plain date: "yyy-mm-dd"
            var hours = '0'; var mins = '0'; }
        // Date.UTC(yy,mm,dd,hh,mm,ss); = milliseconds
    var startStamp = Date.UTC(startRaw[0],startRaw[1]-1,startRaw[2],hours,mins,0)/1000;
            // work on end date
        if (/ /g.test(tmp.val)) { // with time: "yyy-mm-dd HH:MM" - 24hr clock
            var endRaw = tmp.val.split(' ')[0].split('-');
            var timeRaw = tmp.val.split(' ')[1].split(':');
                var hours = timeRaw[0];
                var mins = timeRaw[1]; }
        else { var endRaw = tmp.val.split('-'); // plain date: "yyy-mm-dd"
            var hours = '0'; var mins = '0'; }
    var endStamp = Date.UTC(endRaw[0],endRaw[1]-1,endRaw[2],hours,mins,0)/1000;
            return endStamp >= startStamp || messages.mustPostDate; }
       else return; // startDate not yet set
    },
// etc...
  }; // END Validator =

I think that's it.

@hsnaydd
Copy link
Owner

hsnaydd commented Oct 20, 2016

This can be added as an example in the next version. It can be followed #44.

@hsnaydd hsnaydd closed this as completed Oct 20, 2016
@hsnaydd hsnaydd mentioned this issue Oct 20, 2016
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants