User Tools

Site Tools


sample_code:datediff

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sample_code:datediff [2016/07/23 08:17]
stevegarman tidy
sample_code:datediff [2016/07/29 13:39] (current)
Line 27: Line 27:
  
 // the dateDiff function does not rely on the plugin // the dateDiff function does not rely on the plugin
- 
 app.LoadPlugin( "UIExtras" ); app.LoadPlugin( "UIExtras" );
 var date1,date2; var date1,date2;
Line 155: Line 154:
         ret.sign = "-";         ret.sign = "-";
     }     }
 + 
     // populate variables for comparison     // populate variables for comparison
     var year1 = dt1.getFullYear();     var year1 = dt1.getFullYear();
Line 167: Line 166:
  
     // calculate differences     // calculate differences
-    ret['years'= year2 - year1; +    ret.years = year2 - year1; 
-    ret['months'= month2 - month1; +    ret.months = month2 - month1; 
-    ret['days'= day2 - day1; +    ret.days = day2 - day1; 
 + 
     // cope with any negative values.     // cope with any negative values.
-    if (ret['days'< 0)+    if (ret.days < 0)
     {     {
         // can't span months by arithmetic, use temp date         // can't span months by arithmetic, use temp date
         var dtmp = new Date(dt1.getFullYear(), dt1.getMonth() + 1, 1, 0, 0, -1);         var dtmp = new Date(dt1.getFullYear(), dt1.getMonth() + 1, 1, 0, 0, -1);
- 
         var numDays = dtmp.getDate();         var numDays = dtmp.getDate();
- +  
-        ret['months'-= 1; +        ret.months -= 1; 
-        ret['days'+= numDays; +        ret.days += numDays;
     }     }
 + 
     // months is pure arithmetic     // months is pure arithmetic
-    if (ret['months'< 0)+    if (ret.months < 0)
     {     {
-        ret['months'+= 12; +        ret.months += 12; 
-        ret['years'-= 1;+        ret.years -= 1;
     }     }
  
sample_code/datediff.1469261832.txt.gz · Last modified: 2016/07/23 16:17 (external edit)