Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
Verify date entered on a PDF form is start of a pay period

Working on a PDF form in LiveCycle Designer, I have a field where employees will enter the proposed effective date for a schedule change. These can only be effective on the start of a pay period, which is every other Sunday. (For reference, Sunday, Jan 30, 2022 is a start of a pay period.)

I've tried very many ways of using if statements and the date.getDay() method, but I find that the getDay method sometimes returns the wrong number (the employee enters a date for a Sunday, but the code gets a getDay value of 1 instead of 0). I assume this has something to do with the local time, but not sure.

For reference, here is the code I currently have in my change event. I can't say for sure the rest of it works, as I can't get past the getDay problem. Anyway, appreciate either a fix to my getDay problem, or a more elegant solution to this whole problem that avoids it.

topmostSubform.Page1.Artifact[3].dateEffective::change - (JavaScript, client)

// Check if entered date is a Sunday at the start of a pay period.
// For reference, Sunday 1/30/2022 is the start of a pay period.

// perform this check only if something is entered in this field
xfa.host.messageBox('Value: ' + xfa.event.newText);
xfa.host.messageBox('Is an entry?: ' + !(!xfa.event.newText));
if (!(!xfa.event.newText)) {

    const myRefDate = new Date(2022, 1, 30);
    const myDate = new Date(xfa.event.newText);
    xfa.host.messageBox('Day: ' + myDate.getDay()); 
    
    // first check if entered date is a Sunday.  If so, then execute the other code.
    if (myDate.getDay() == 0) {

        const diffTime = Math.abs(myRefDate - myDate);
        xfa.host.messageBox('diffTime: ' + diffTime);
        const diffDays = diffTime / (1000 * 60 * 60 * 24); // includes fractional days
        xfa.host.messageBox('diffDays: ' + diffDays);
        const diffPP = diffDays / 14; // includes fractional parts of a 14-day pay period
        xfa.host.messageBox('diffPP: ' + diffPP);
        const remainderPP = diffPP % 1; // calculate remainder of diffPP
        xfa.host.messageBox('remainderPP: ' + remainderPP);
        
        // if the remainderPP value indicates that myDate is more than 1 day from a Sunday, then fail
        if (remainderPP * 14 > 1) {
            // messagebox with error
            xfa.host.messageBox('Error1: You must enter the date for a Sunday that is the start of a pay period.  Check your Pay/Holiday Schedule.');
            xfa.host.setFocus(this.name);
        }
    }else{
        xfa.host.messageBox('Error2: You must enter the date for a Sunday that is the start of a pay period.  Check your Pay/Holiday Schedule.');
        xfa.host.setFocus(this.name);
    }
    
};
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda