| | 68 | } |
| | 69 | |
| | 70 | /** |
| | 71 | * Returns the difference between this object and given one in provided units |
| | 72 | * Difference is calculated as FLOOR(this - dateUtil) |
| | 73 | * @param dateUtil - DateUtil instance to be compared |
| | 74 | * @param units - Type of unit to be used while calculation, one of MILLISECONDS, SECONDS, MINUTES, HOURS, DAY/DATE |
| | 75 | * @return |
| | 76 | */ |
| | 77 | public function diff(dateUtil:DateUtil, units:DateProperty):Number{ |
| | 78 | var difference:Number = this.date_.time - dateUtil.timestamp; |
| | 79 | if(DateProperty.MILLISECONDS.equals(units)){ |
| | 80 | return difference; |
| | 81 | } else if(DateProperty.SECONDS.equals(units)){ |
| | 82 | return Math.floor( difference/MILLISECOND_PER_SECOND ); |
| | 83 | } else if(DateProperty.MINUTES.equals(units)){ |
| | 84 | return Math.floor( difference/MILLISECOND_PER_MINUTE ); |
| | 85 | } else if(DateProperty.HOURS.equals(units)){ |
| | 86 | return Math.floor( difference/MILLISECOND_PER_HOUR ); |
| | 87 | } else if(DateProperty.DAY.equals(units) || DateProperty.DATE.equals(units)){ |
| | 88 | return Math.floor( difference/MILLISECOND_PER_DAY ); |
| | 89 | } |
| | 90 | return 0; |