/**
 * Author: Bruno Germano
 * Date: 2015-11-13 16:30
 * URL: https://github.com/egermano/jquery.dateAgo
 */

 /**
  * Date Ago
  * @param  string input
  * @param  object options
  * @return string formated string
  */
angular.module('egermano.dateAgo', [])
  .filter('dateAgo', function() {
    return function(input){
      if (!input) return input;

      var options = {};
      if (arguments[1]) options = arguments[1];

      // This is the easiest way to have default options.
      var settings = $.extend({
        texts: {
          now: 'just now',
          minutes: 'minutes ago',
          hour: 'hour ago',
          hours: 'hours ago',
          yesterday: 'yesterday',
          days: 'days ago'
        }
      }, options );


      var baseDate = input;

      //date from menssage
      var date = new Date(Date.parse(baseDate)).toLocaleDateString(),
          hour = new Date(Date.parse(baseDate)).toLocaleTimeString(),
          _agoDate = new Date(date + ' ' + hour),
          today = new Date(),

          diff = (today.getTime()-_agoDate.getTime()),
          dataText = '';

      if(diff<(1000*60*60*24)){
          if(diff<(1000*60*60)){
              var minutes = Math.floor(diff/(1000*60));
              if(minutes <= 1)
                  dataText = settings.texts.now;
              else
                  dataText = minutes.toString() + ' ' + settings.texts.minutes;
          }else{
              var hours = Math.floor(diff/(1000*60*60));
              dataText = hours.toString() + (hours==1?' ' + settings.texts.hour:' ' + settings.texts.hours);
          }
      }else{
          var days = Math.floor(diff/(1000*60*60*24));
          if(days==1)
              dataText = settings.texts.yesterday;
          else
              dataText = days.toString() + ' ' + settings.texts.days;
      }

      return dataText;
    }
  });

@@ -739,17 +739,16 @@
 ons );%0A%0A
-%0A
       va
@@ -761,24 +761,39 @@
 Date = input
+.split(/-%7CT%7C:/)
 ;%0A%0A      //d
@@ -803,17 +803,16 @@
  from me
-n
 ssage%0A  
@@ -835,35 +835,52 @@
 ew Date(
-Date.parse(
+baseDate%5B0%5D, baseDate%5B1%5D-1, 
 baseDate
 )).toLoc
@@ -863,33 +863,35 @@
 e%5B1%5D-1, baseDate
-)
+%5B2%5D
 ).toLocaleDateSt
@@ -889,32 +889,51 @@
 aleDateString(),
+ //month is 0-based
 %0A          hour 
@@ -947,28 +947,99 @@
 ate(
-Date.parse(baseDate)
+baseDate%5B0%5D, baseDate%5B1%5D-1, baseDate%5B2%5D, baseDate%5B3%5D, baseDate%5B4%5D, baseDate%5B5%5D, baseDate%5B6%5D
 ).to
@@ -1978,15 +1978,16 @@
 t;%0A    %7D
+;
 %0A  %7D);%0A

fix safari issue