Explore the community Forums Lectora Lectora Questions & Answers Date Calculations in Lectora

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #316088 Score: 0
    Profile photo of clammers
    clammers
    Member
    beginner
    intermediate
    contributor
    curious george
    wise owl
    picture perfect
    friend finder
    advanced
    entry
    entry
    20 pts
    @clammers

    Does anybody have experience with date calculations in Lectora? I am looking to perform a comparison between two dates: a date set in the past and the current date. If the difference between the two is greater than X, I want to update a variable.

    For example, if I create a blank variable as Completion_Date, I want to update this variable with the current date the first time a user completes the course. This date would not update unless a 30 day time period has passed. If this time period has passed, the Completion_Date would update with that new date.

    In context: A user completes a course on 5/1/2016 and their Completion_Date is marked as such. If they go in on 5/2/2016 – 5/31/2016, the Completion_Date would remain the same. If, however, they go in on 6/1/2016, I would like the Completion_Date to update to 6/1/2016.

    I realize the simple answer to this is LMS management, but I am more just curious to see if there is a simple way to achieve this in Lectora. When I look at the conditions in Lectora, I see the comparative clauses (Relationships), but how can I interpret the text date (Thursday, May 26, 2016) into a string (05262016) on which to perform the calculation?

    #316129 Score: 0
    Profile photo of Sergey Snegirev
    Sergey Snegirev
    Member
    contributor
    intermediate
    advanced
    friend finder
    lab member
    junior moderator
    advocate
    LUC16
    LUC16 Attendee
    wise owl
    339 pts
    @ssneg

    I did this demo (attached) a long time ago for someone on the Lectora forums. See if it is of any use, please don’t hesitate to ask questions if you need help.

    Attachments:
    1. Title-1.awt_.zip
    #316159 Score: 0
    Profile photo of Jennifer Valley
    Jennifer Valley
    Member
    contributor
    beginner
    friend finder
    advanced
    lectora beginner
    verified member
    wise owl
    profile
    picture perfect
    curious george
    114 pts
    @jvalley4735

    I attended an LUC session where we talked about a similar topic.  We created a variable called CurrentDate and used the LMS variable to find the current date based on our computers.  Then added another variable for the submission date. We then said that if current date is not equal to your submit date then prompt this message.  If you applied the same principals you could also trigger a variable change or other type of action.

    #316523 Score: 0
    Profile photo of clammers
    clammers
    Member
    beginner
    intermediate
    contributor
    curious george
    wise owl
    picture perfect
    friend finder
    advanced
    entry
    entry
    20 pts
    @clammers

    Thank you both. I have yet to do a deep-dive on Sergey’s suggestion, but I will give it a shot. As to your suggestion, Jennifer, that’s more or less how I’m performing this task today; however, I don’t think this quite fits my need. Where would the elapsed time period calculation come into place?

    If I completed a course a week ago, the LMS would have recorded the Completion Date at 5/24/2016. I want to show this date in the course (we’ll call it, “Finish Date”). I can use a variable to check against that date and populate the current date (5/31/2016)  but I don’t want it to do so until 30 days have passed. Meaning, I don’t want that “Finish Date” to change unless it is 6/23/2016.

    #328322 Score: 0
    Profile photo of Michael Smith
    Michael Smith
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    @msmith2572

    I am working on something similar, but I am having an issue with the JavaScript updating the Lector variables.

    Based on the Example Sergey provided, (not changing variable names to keep it simple) I am setting the user defined variable  “MyMonkeyExpired” = “0” first to make sure the variable is initialized each time I load the page. Then I run the JavaScript Provided by Sergey

    var d = new Date();
    var ex = new Date(“09/26/2016”); //set this by hand as MM/DD/YYYY
    Math.floor((Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())-Date.UTC(ex.getFullYear(), ex.getMonth(), ex.getDate()))/(1000*60*60*24))> 45?
    VarMyMonkeyExpired.set =(‘YES’) : VarMyMonkeyExpired.set = (‘NO’);

    Then Based on the value of “MyMonkeyExpired” I display a popup.  I am finding that once I set the value of “MyMonkeyExpired” to “0”, the JavaScript is not changing the variable to “Yes” or “No”.   I tested the code in a tool on http://www.w3schools.com and it appears to work great there using a slight alteration of the variable to reference an object on that site.

    So my question, is “VarMyMonkeyExpired.set =(‘YES’) : VarMyMonkeyExpired.set = (‘NO’);” the proper way of setting a user defined variable from JavaScript?

     

    • This reply was modified 3 years, 5 months ago by Profile photo of Michael Smith Michael Smith.
    • This reply was modified 3 years, 5 months ago by Profile photo of Michael Smith Michael Smith.
    • This reply was modified 3 years, 5 months ago by Profile photo of Michael Smith Michael Smith.
    #328563 Score: 0
    Profile photo of Michael Smith
    Michael Smith
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    @msmith2572

    I got this working, but I had to change the code slightly. It appears the “=” was causing me grief.  While I was tweaking I updated the variables and changed the “if -else” so other developers could follow along behind me a little easier.

    var d = new Date();

    var ex = new Date(“7/15/2016”); //    <<———–  set this by hand as MM/DD/YYYY this should be the approximate go live date

    if(Math.floor((Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())-Date.UTC(ex.getFullYear(), ex.getMonth(), ex.getDate()))/(1000*60*60*24))  > 45)
    {
    Var_RevisionDate.set(‘True’);
    }
    else
    {
    Var_RevisionDate.set(‘False’);
    }

    What I would like to do is grab the lectora “PublishDate” and use that for my comparison so I do not need a developer to enter a date.  I am having a problem getting the date in a format needed to calculate it.

    #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, 1 month ago by Profile photo of Gary Burdette Gary Burdette.
    • This reply was modified 2 years, 1 month ago by Profile photo of Gary Burdette Gary Burdette.
    Attachments:
    1. Title_2.zip
    #381660 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    47 pts
    @JasonADal

    Since I’m home, I can’t look at your sample – However, I had what I think is a similar question several months ago where I wanted to set a drop down to display a range of dates based on the current date:

    Dynamic date as initial value…

    If I understand correctly, you’re getting the date that the user last took the course then restricting retaking it for 10 days from the initial completion date. Using a similar method, you could change the “-30” to “-10” and do the compare, thus overcoming the need for the math function. The tricky part might be if the user took the course on 1/30 and is trying again on 2/10, which is technically 11 days later.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.