javascript moment.js script not working quite right


javascript moment.js script not working quite right



The code below: if ( exDate.isBefore( today ) || !exDate) --> the !exDate code doesn't work. Can anyone help me? I am trying to caculate the ef FEE based on the expires date. http://verlager.com/account-pure.php The code has to include ** member > "" **


function calcEntryFee( elem ) {
var idx, member, exDate, today, fee;

elem = elem || {};
if ( /^[PEMX](d+)$/.test( elem.id ) ) {
idx = RegExp.$1;
} else {
return false;
}

member = getMemberData( jQuery( '#P' + idx ).val() );
mmfee = parseFloat( jQuery( '#M' + idx ).val() );
//exDate = moment( member.Expires, 'YYYY.MM.DD' );
exDate = member && member.Expires && member.Expires !== '' ? moment( member.Expires, 'YYYY.MM.DD' ) : null
today = moment();
fee = '';

if ( (!exDate || !exDate.isValid() || exDate.isBefore( today )) && (member.Name > '')) {fee = 5;} // this just doesn't work.

if (!exDate)
{
fee = 5;
} else if ( exDate.isSameOrAfter( today ) ) {
fee = 3;
} else if ( ! member.Expires && mmfee > 0 ) {
fee = 0;
}

// Updates the entry fee input value.
jQuery( '#E' + idx ).val( fee );

return fee;
}





try changing order and adding valid check: if ( !exDate || !exDate.isValid() || exDate.isBefore( today ))
– Ovidiu Dolha
May 3 at 8:52


if ( !exDate || !exDate.isValid() || exDate.isBefore( today ))





very close I believe. But it has to include non-blank member only.
– verlager
May 3 at 8:55





In other words, the criteria for 5 has to be a non-blank member input field
– verlager
May 3 at 8:56





then just do something like exDate = member && member.Expires && member.Expires !== '' ? moment( member.Expires, 'YYYY.MM.DD' ) : null - that will also make sense of the !exDate condition which you could have removed otherwise
– Ovidiu Dolha
May 3 at 8:58


exDate = member && member.Expires && member.Expires !== '' ? moment( member.Expires, 'YYYY.MM.DD' ) : null


!exDate





I posted your code and tried it but it didn't work.
– verlager
May 3 at 9:07




1 Answer
1



I had this exact problem. I ended up using moment-range. Based on your code sample, perhaps you could check the expiration like this:


import Moment from 'moment'
import { extendMoment } from 'moment-range'

const moment = extendMoment(Moment)

export default (expires) => {
const momentExpires = moment(expires, 'YYYY.MM.DD')
const now = moment()

const expirationCheck = moment.range(now.format(), momentExpires.format())

return {
expired: expirationCheck.valueOf() < 0
}
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails