• Problems with the fuzzy dates

    By Henrik Tornblom 1 decade ago

    I had problems with the fuzzy dates on my server. They read like: "undefined minutes ago".



    After some debugging it seems that the @Text() formula cant handle the conversion to text from the numbers. My theaory about this is that there is some problem with the Swedish decimal comma and not the more international decimal full stop.



    By removing the @Text formulas and rely on the javascript conversion it works. Code like:



    /**

     * =======================================================<br/>
     * &lt;HEADER&gt;<br/>
     * NAME:    xpDates server side javascript library<br/>
     * VERSION: 20090627<br/>
     * AUTHOR(S):   Matt White<br/>
    

    * ORIGINAL SOURCE: http://mattwhite.me

                        based upon code from Jake Howlett:<br/>
    

    http://www.codestore.net/store.nsf/unid/BLOG-20080909?OpenDocument

     * HISTORY:<br/>
     * 20090627:    initial version<br/>
     * <br/>
     * USAGE<br/>
     * var d = new DateHelper()<br/>
     * var datestring = d.timeSince(document1.getItemValueDateTimeArray().elementAt(0), true);<br/>
     * <br/>
     * DISCLAIMER:<br/>
     * This code is provided &quot;as-is&quot;, and should be used at your own risk. <br/>
     * The authors make no express or implied warranty about anything, <br/>
     * and they will not be responsible or liable for any damage caused by <br/>
     * the use or misuse of this code or its byproducts. No guarantees are <br/>
     * made about anything.<br/>
     *<br/>
     * That being said, you can use, modify, and distribute this code in any<br/>
     * way you want, as long as you keep this header section intact and in<br/>
     * a prominent place in the code.<br/>
     * &lt;/HEADER&gt;<br/>
     * =======================================================<br/>
    

    */



    DateHelper = function() {

    var dt_then:NotesDateTime = null;<br/>
    var dt_now:NotesDateTime = session.createDateTime(&quot;Today&quot;);<br/>
    dt_now.setNow();<br/>
    var diff_in_seconds = 0;<br/>
    var diff_in_minutes = 0;<br/>
    var whichway = &quot;&quot;;<br/>
    var since = &quot;&quot;;<br/>
    <br/>
    this.prototype.timeSince = function(datetime, includeseconds){<br/>
        dt_then = session.createDateTime(@Text(datetime));<br/>
        var future = false;<br/>
        diff_in_seconds = dt_now.timeDifference(dt_then);<br/>
        <br/>
        if (diff_in_seconds &lt; 0){<br/>
            future = true;  <br/>
            diff_in_seconds = diff_in_seconds;<br/>
            whichway = &quot; away&quot;;<br/>
        }else{<br/>
            future = false;<br/>
            whichway = &quot; ago&quot;;<br/>
        }<br/>
                <br/>
        diff_in_minutes = @Round((diff_in_seconds/60));<br/>
                <br/>
        if(diff_in_minutes &gt;= 0 &amp;&amp; diff_in_minutes &lt;= 1){<br/>
            if (!includeseconds){<br/>
                if(diff_in_minutes == 0)<br/>
                    since = &quot;less than a minute&quot;;<br/>
                else<br/>
                    since = &quot;1 minute&quot;;<br/>
            }else{<br/>
                if(diff_in_seconds &gt;= 0 &amp;&amp; diff_in_seconds &lt;= 4)<br/>
                    since = &quot;less than 5 seconds&quot;;<br/>
                else if(diff_in_seconds &gt;= 5 &amp;&amp; diff_in_seconds &lt;= 9)<br/>
                    since = &quot;less than 10 seconds&quot;;<br/>
                else if(diff_in_seconds &gt;= 10 &amp;&amp; diff_in_seconds &lt;= 19)<br/>
                    since = &quot;less than 20 seconds&quot;;<br/>
                else if(diff_in_seconds &gt;= 20 &amp;&amp; diff_in_seconds &lt;= 39)<br/>
                    since = &quot;half a minute&quot;;<br/>
                else if(diff_in_seconds &gt;= 40 &amp;&amp; diff_in_seconds &lt;= 59)<br/>
                    since = &quot;less than a minute&quot;;<br/>
                else <br/>
                    since = &quot;1 minute&quot;;<br/>
            } <br/>
        }else if(diff_in_minutes &gt;= 2 &amp;&amp; diff_in_minutes &lt;= 44) <br/>
                since =  diff_in_minutes + &quot; minutes&quot;;<br/>
        else if(diff_in_minutes &gt;= 45 &amp;&amp; diff_in_minutes &lt;= 89)<br/>
            since = &quot;about 1 hour&quot;;<br/>
        else if(diff_in_minutes &gt;= 90 &amp;&amp; diff_in_minutes &lt;= 1439)<br/>
            since = &quot;about &quot; + @Round(diff_in_minutes/ 60) + &quot; hours&quot;;<br/>
        else if(diff_in_minutes &gt;= 1440 &amp;&amp; diff_in_minutes &lt;= 2879)<br/>
            since = &quot;1 day&quot;;<br/>
        else if(diff_in_minutes &gt;= 2880 &amp;&amp; diff_in_minutes &lt;= 43199)<br/>
            since = &quot;about &quot; + @Round(diff_in_minutes/ 1440) + &quot; days&quot;;<br/>
        else if(diff_in_minutes &gt;= 43200 &amp;&amp; diff_in_minutes &lt;= 86399)<br/>
            since = &quot;about 1 month&quot;;<br/>
        else if(diff_in_minutes &gt;= 86400 &amp;&amp; diff_in_minutes &lt;= 525599)<br/>
            since = @Round(diff_in_minutes/ 43200) + &quot; months&quot;;<br/>
        else if(diff_in_minutes &gt;= 525600 &amp;&amp; diff_in_minutes &lt;= 1051199)<br/>
            since = &quot;about 1 year&quot;;<br/>
        else <br/>
            since = &quot;over &quot; + @Round(diff_in_minutes/ 525600) + &quot; years&quot;;<br/>
    <br/>
        return since + whichway;<br/>
    }<br/>
    

    }