Forum Discussion

jonathancrow's avatar
14 years ago
Solved

Open new window if user hasn't seen an article

I would like to create a function where a new window pops up to encourage people to answer the question of the week. But I don't want to overly annoy people.   I added the article "Question of the ...
  • AdamN's avatar
    AdamN
    14 years ago

    Hi Jonathan,


    What you're experiencing is likely a data truncation issue with these two lines:

     

    <#assign date_visit = rest("/users/id/" + my_userid + "/last_visit_time").value?datetime("yyyy-MM-dd") />
    <#assign my_topic_posttime = topic.post_time?datetime("yyyy-MM-dd") />

     Because of the "yyyy-MM-dd" timestamp format, it's only picking up the year, month, and date. If you want a more specific date/time you'll need to alter this format (ie. to account for hours, minutes, seconds). Perhaps something like this: "yyyy-MM-dd'T'HH:mm:ssZ"

  • AdamN's avatar
    AdamN
    14 years ago

    Hi Jonathan,

     

    Since the REST API returns the date in GMT+0, I'd suggest getting "now" in GMT+0 as well instead of trying to convert the result to the local timezone.

     

    Here's some sample code I came up with showing how to get the current time in GMT+0 (you'll probably be more interested in the milliseconds version):

     

    <#assign utcDateTime = .now?iso_utc?datetime("yyyy-MM-dd'T'HH:mm:ss") />
    <#assign utcDateTime_number = datesupport.setDate(utcDateTime).millisecondsAsString?number />
    utcDateTime: ${utcDateTime}<br />
    utcDateTime_number: ${utcDateTime_number}<br />

     I hope this helps!