• Resolved ensemblebd

    (@ensemblebd)


    Hi, you’re plugin is producing date stamps with 1 month off.

    It’s caused by the minified javascript you have, which submits to:
    /wp-admin/admin-ajax.php?action=ai1ec_front_end_submit_event

    with the parameter:
    name=”ai1ec_end_time”
    2015-07-10 0:00:00

    for example. Which when input on the actual form, is NOT in July (7), but in June(6). This occurs in Chrome, and Firefox. The plugin doesn’t work (period) in IE9, so I can’t verify integrity on that browser (one of the reasons I have it installed on my machine).

    But I am about to debug your javascript which is brutal because it’s minified, and you don’t offer unminified version.

    And I’m letting you know it’s broken, and would appreciate any feedback on what might be causing this?
    How is it that no one else has reported this problem?
    My first thought was the browser culprit – where the months are either zero based index, or not. But you are converting it to unix timestamp, and I’m having to debug to locate where the actual issue is.
    new Date() in js is not reliable. And you shouldn’t be using it unless you have browser detection.

    https://www.ads-software.com/plugins/all-in-one-event-calendar/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter ensemblebd

    (@ensemblebd)

    Tracked it down. You use moment.js , which converts the date string into a unix timestamp.
    And the unix timestamp is wrong.

    Whether this is your fault or moment.js fault is to be determined.
    I unminified your minified script which is injected into the loaded singular javascript file on page load. Then added some console.log to it, and began debugging.
    Below is the code altered that proves the unix timestamp returned from moment.js is WRONG by 1 month.

    y = function() {
                        var t = e("#ai1ec-start-date-input",
                                f),
                            n = e("#ai1ec-end-date-input",
                                f),
                            r = e("#ai1ec-start-time-input",
                                f),
                            i = e("#ai1ec-end-time-input",
                                f),
                            s = e("#ai1ec-has-time",
                                f)[0].checked,
                            o = t.val(),
                            a = r.val(),
                            l = n.val(),
                            c = i.val(),
                            h = "",
                            p = "",
                            d,
                            v,
                            m,
                            g = f.data("ai1ecStartTime"),
                            y = f.data("ai1ecEndTime"),
                            b = !1;
    						console.log('t: ');console.log(t);
                        typeof g == "undefined" && (g = ""),
                            typeof y == "undefined" && (y = ""),
                            d = t.data("dateFormat").toUpperCase(),
                            r.data("showMeridian") ? v = "hh:mm A" : v = "HH:mm",
                            m = d + " " + v,
                            o !== "" && (s && a !== "" ? h = u(o + " " + a,m) : h = u(o,d),
                                h = h.unix()),
                            h === "" || g !== "" && parseInt(g,
                                10) === h ? l !== "" && (s && c !== "" ? p = u(l + " " + c,
                                    m) : p = u(l,
                                    d),
                                p = p.unix(),
                                p < h && (p = h,
                                    b = !0)) : (g === "" ? g = h : g = parseInt(g,
                                    10),
                                y === "" ? y = g : y = parseInt(y,
                                    10),
                                p = h + y - g,
                                b = !0);
                        if (b) {
                            var w = u.unix(p);
                            n.val(w.format(d)).datepicker("update").datepicker("setStartDate",
                                    o),
                                s && a !== "" && i.val(w.format(v))
                        }
    					console.log('h: '+h); // INVALID TIMESTAMP 1 MONTH OFF
    					try {
    						console.log(u);// moment.js function.
    						console.log(o);// the date string. ITS VALID. Not wrong.
    						console.log(a); // unknown empty string
    						console.log(m); // the date format.
    
    						console.log('---------------------------');
    						console.log('1: '+(u(o + " " + a,m))); // timestamp 1, both identical, both wrong
    						console.log('2: '+ (u(o,d))); // timestamp 2 , both identical, both wrong
    						console.log('3: '+ (h.unix())); // null, not used, unknown.
    					}catch(e) {console.log(e);}
    
                        f.data("ai1ecStartTime",
                                h),
                            f.data("ai1ecEndTime", p)
    Thread Starter ensemblebd

    (@ensemblebd)

    Proof that it is caused inside moment.js, which by the way is a very old version of it.
    (wp-content/plugins/all-in-one-event-calendar/public/js/external_libs/moment.js)
    This is console output. You can see that it returns the wrong date 90% of the time.

    $
    $(e, t)
    $(t="6/10/2015",n)
    Fri Jul 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="5/10/2015",n)
    Sun May 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="6/10/2015",n)
    Fri Jul 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="4/10/2015",n)
    Sun May 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="1/10/2015",n)
    Sat Jan 10 2015 00:00:00 GMT-0600 (Central Standard Time)
    
    $(t="2/10/2015",n)
    Tue Mar 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="02/10/2015",n)
    Tue Mar 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="02/10/2015",n="MM/DD/YYYY")
    Tue Mar 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="22/10/2015",n="MM/DD/YYYY")
    Mon Oct 10 2016 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="00/10/2015",n="MM/DD/YYYY")
    Wed Dec 10 2014 00:00:00 GMT-0600 (Central Standard Time)
    
    $(t="01/10/2015",n="MM/DD/YYYY")
    Sat Jan 10 2015 00:00:00 GMT-0600 (Central Standard Time)
    
    $(t="02/10/2015",n="MM/DD/YYYY")
    Tue Mar 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    
    $(t="03/10/2015",n="MM/DD/YYYY")
    Tue Mar 10 2015 00:00:00 GMT-0500 (Central Daylight Time)
    Thread Starter ensemblebd

    (@ensemblebd)

    The following function is causing the malfunction

    moment.js, unminified, cleaned, rewritten:

    function I(e, t, n, r) {
        var i, s, o = [];
        for (i = 0; i < 7; i++) {
            o[i] = e[i] = e[i] == null ? i === 2 ? 1 : 0 : e[i];
        }
    
    	o[7] = t;
    	e[7] = o[7];
    	if (e[8] != null) {
    		o[8] = e[8];
    	}
    	if (n) {
    		e[3]+=n;
    	} else e[3]=0;
    	if (r) {
    		e[4]+=r;
    	} else e[4]=0;
    	s = new Date(0);
    	if (t) {
    		s.setYear(e[0]);
    		s.setUTCMonth(e[1]);
    		s.setUTCDate(e[2]);
    		s.setUTCHours(e[3], e[4], e[5], e[6]);
    	} else {
    		s.setYear(e[0]);
    		s.setMonth(e[1]); // THIS ONE DOES IT.
    		s.setDate(e[2]);
    		s.setHours(e[3], e[4], e[5], e[6]);
    	}
    	s._a = o;
        return s;
    }

    So I am going to have to modify moment.js in your plugin to fix this, and stop wordpress from updating your software at this time unfortunately.

    When I whittled it down, the following code in chrome browser console reproduces the problem:

    s = new Date(0); s.setYear(2015); s
    Thu Dec 31 2015 18:00:00 GMT-0600 (Central Standard Time)
    
    s.setMonth(5); s
    Wed Jul 01 2015 18:00:00 GMT-0500 (Central Daylight Time)
    
    s.setMonth(6); s
    Wed Jul 01 2015 18:00:00 GMT-0500 (Central Daylight Time)

    Please explain that.

    Thread Starter ensemblebd

    (@ensemblebd)

    So for anyone having this issue. Change this code:
    new Date(0)

    To this:
    new Date()

    Problem solved.

    https://stackoverflow.com/questions/30788920/javascript-date-function-abnormalities

    Hi,

    In a few days we will release an upgrade and this bug will be fixed.

    Thread Starter ensemblebd

    (@ensemblebd)

    Wonderful, thank you for the support!

    No problem ??

    Hi Benjamin,

    A month ago you said this issue would be resolved in a few days… Can we ever expect an update that will make this calendar usable again?

    Please advise.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Front End Submit, Events off by 1month’ is closed to new replies.