Explore the community Forums Lectora Lectora Questions & Answers Date Calculations in Lectora Reply To: Date Calculations in Lectora

#381382 Score: 0
Profile photo of Gary Burdette
Gary Burdette
Member
beginner
intermediate
friend finder
LUC16 Attendee
curious george
picture perfect
wise owl
profile
Group Member
advanced
@GBurdette

<p>I ran across this post because someone wanted to set up a situation where the student can’t repeat a course or test within ten days.</p><p>As I struggled to make the example work, I realized we don’t need jump through the hoops of parsing the date and finding the UTC if we do everything in UTC.  Because no one really needs to see the date in question.</p><p>You will need two Lectora variables.  I used _retakeDate and _todaysDate</p><p>The first time the student takes the test/course, this JavaScript is triggered:</p><pre style=”padding-left: 30px;”>Var_retakeDate.set(Math.round(new Date().getTime() / 1000)+864000);<p>That stores that moment in time as seconds (since 1/1/1970) plus 10 days worth of seconds.</p><p>When the student enters the page where the test/course would be available, this is an OnPageShow action:</p><pre style=”padding-left: 30px;”>Var_todaysDate.set(Math.round(new Date().getTime() / 1000));<p>That stores right now as seconds.</p><p>Before you show a button or whatever allowing the student to proceed, have a condition that checks to see if _todaysDate is greater than _retakeDate.  If it is, then it is OK to proceed.</p><p>If I had a hard date to compare to, I would convert that to seconds, subtract from _todaysDate and see if that was <0.  But for our situation, the target date would always be different, and needs to be remembered so it is stored as a Lectora variable.</p><p>I have attached an example that I created while playing around.</p>

  • This reply was modified 2 years, 8 months ago by Profile photo of Gary Burdette Gary Burdette.
  • This reply was modified 2 years, 8 months ago by Profile photo of Gary Burdette Gary Burdette.
Attachments:
  1. Title_2.zip