/*
The formatDate function outputs the Years, Days, Hours, Minutes,
Seconds, and Milliseconds
554054
function formatDate(ms) {
  if (typeof ms !== 'number') {
    throw new TypeError('Expected a number');
  }

  return {
    years: Math.floor(ms / 31536000000),
    days: Math.floor(ms / 86400000 % 365),
    hours: Math.floor(ms / 3600000 % 24),
    minutes: Math.floor(ms / 60000 % 60),
    seconds: Math.floor(ms / 1000 % 60),
    milliseconds: Math.floor(ms % 1000)
  };
}
521556
function (timeFormat) {
				var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
					orders = {
						h: -1,
						m: -1,
						s: -1,
						l: -1,
						c: -1,
						t: -1,
						z: -1
					};

				if (finds) {
					for (var i = 0; i < finds.length; i++) {
						if (orders[finds[i].toString().charAt(0)] === -1) {
							orders[finds[i].toString().charAt(0)] = i + 1;
						}
					}
				}
				return orders;
			}
655779
function formatDate(date) {
  let timestamp;
  if (date instanceof Date) {
    // Datadog expects seconds.
    timestamp = Math.round(date.getTime() / 1000);
  } else if (date instanceof Number) {
    // Make sure it is an integer, not a float.
    timestamp = Math.round(date);
  }
  return timestamp;
}
46303
public static String formatMillis(double theMillis) {
		StringBuilder buf = new StringBuilder(20);
		if (theMillis > 0.0 && theMillis < 1.0) {
			buf.append(getSubMillisecondMillisFormat().format(theMillis));
			buf.append("ms");
		} else if (theMillis < (10 * DateUtils.MILLIS_PER_SECOND)) {
			buf.append((int) theMillis);
			buf.append("ms");
		} else if (theMillis >= DateUtils.MILLIS_PER_DAY) {
			double days = theMillis / DateUtils.MILLIS_PER_DAY;
			if (days >= 10) {
				buf.append(getTenDayFormat().format(days));
				buf.append(" days");
			} else if (days != 1.0f) {
				buf.append(getDayFormat().format(days));
				buf.append(" days");
			} else {
				buf.append(getDayFormat().format(days));
				buf.append(" day");
			}
		} else {
			long millisAsLong = (long) theMillis;
			append(buf, "", 2, ((millisAsLong % DateUtils.MILLIS_PER_DAY) / DateUtils.MILLIS_PER_HOUR));
			append(buf, ":", 2, ((millisAsLong % DateUtils.MILLIS_PER_HOUR) / DateUtils.MILLIS_PER_MINUTE));
			append(buf, ":", 2, ((millisAsLong % DateUtils.MILLIS_PER_MINUTE) / DateUtils.MILLIS_PER_SECOND));
			if (theMillis <= DateUtils.MILLIS_PER_MINUTE) {
				append(buf, ".", 3, (millisAsLong % DateUtils.MILLIS_PER_SECOND));
			}
		}
		return buf.toString();
	}
670274
private String getTimeString(Date value)
   {
      Calendar cal = DateHelper.popCalendar(value);
      int hours = cal.get(Calendar.HOUR_OF_DAY);
      int minutes = cal.get(Calendar.MINUTE);
      DateHelper.pushCalendar(cal);
      
      StringBuilder sb = new StringBuilder(4);
      sb.append(m_twoDigitFormat.format(hours));
      sb.append(m_twoDigitFormat.format(minutes));

      return (sb.toString());
   }
940331
function momentParse( str, formats, options ) {
   const origParseTwoDigitYear = moment.parseTwoDigitYear;
   if( options.dateTwoDigitYearWrap > -1 && options.dateTwoDigitYearWrap < 100 ) {
      moment.parseTwoDigitYear = input => {
         let int = parseInt( input, 10 );
         int = isNaN( int ) ? 0 : int;
         return int + ( int > options.dateTwoDigitYearWrap ? 1900 : 2000 );
      };
   }

   try {
      return moment( str, formats, true );
   }
   finally {
      moment.parseTwoDigitYear = origParseTwoDigitYear;
   }
}
178558
public static void formatDate(StringBuffer buf,Calendar calendar, boolean cookie)
    {
        // "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
        // "EEE, dd-MMM-yy HH:mm:ss 'GMT'",     cookie
        
        int day_of_week  = calendar.get(Calendar.DAY_OF_WEEK);
        int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
        int month = calendar.get(Calendar.MONTH);
        int year = calendar.get(Calendar.YEAR);
        int century = year/100;
        year=year%100;

        long tm = (calendar instanceof HttpCal)?(((HttpCal)calendar).getTimeInMillis()):calendar.getTime().getTime();
        int epoch=(int)((tm/1000) % (60*60*24));
        int seconds=epoch%60;
        epoch=epoch/60;
        int minutes=epoch%60;
        int hours=epoch/60;
        
        buf.append(DAYS[day_of_week]);
        buf.append(',');
        buf.append(' ');
        StringUtil.append2digits(buf,day_of_month);
        
        if (cookie)
        {
            buf.append('-');
            buf.append(MONTHS[month]);
            buf.append('-');
            StringUtil.append2digits(buf,year);
        }
        else
        {
            buf.append(' ');
            buf.append(MONTHS[month]);
            buf.append(' ');
            StringUtil.append2digits(buf,century);
            StringUtil.append2digits(buf,year);
        }
        buf.append(' ');
        StringUtil.append2digits(buf,hours);
        buf.append(':');
        StringUtil.append2digits(buf,minutes);
        buf.append(':');
        StringUtil.append2digits(buf,seconds);
        buf.append(" GMT");
    }
1001046
function CronDate (date) {
		this.milliseconds = date.getMilliseconds();
		this.seconds = date.getSeconds() + 1;
		this.minutes = date.getMinutes();
		this.hours = date.getHours();
		this.days = date.getDate();
		this.months  = date.getMonth();
		this.years = date.getFullYear();
	}
717681
function generateDay(name, day, month, year, zeroes, dateObject) {
  var returnObject = {};

  returnObject.day = day;
  returnObject[name] = name;
  if (zeroes) returnObject.dayFormat = ('0' + day).slice(-2);
  if (dateObject) returnObject.date = new Date(year, month, day);
  return returnObject;
}
1329657
function weekFormat() {

  const format = function(d) {
    return formatWeekYear(d) + "w" + formatWeek(d);
  };

  format.parse = function parse(dateString) {
    const matchedDate = dateString.match(/^(\d{4})w(\d{2})$/);
    return matchedDate ? getDateFromWeek(matchedDate[1], matchedDate[2]) : null;
  };

  const formatWeekYear = function(d) {
    if (!(d instanceof Date)) d = new Date(+d);
    return new Date(+d + ((4 - (d.getUTCDay() || 7)) * 86400000)).getUTCFullYear();
  };

  const formatWeek = function(d) {
    if (!(d instanceof Date)) d = new Date(+d);
    const quote = new Date(+d + ((4 - (d.getUTCDay() || 7)) * 86400000));
    const week = Math.ceil(((quote.getTime() - quote.setUTCMonth(0, 1)) / 86400000 + 1) / 7);
    return week < 10 ? "0" + week : week;
  };

  const getDateFromWeek = function(p1, p2) {
    const week = parseInt(p2);
    const year = p1;
    const startDateOfYear = new Date(); // always 4th of January (according to standard ISO 8601)
    startDateOfYear.setUTCFullYear(year);
    startDateOfYear.setUTCMonth(0);
    startDateOfYear.setUTCDate(4);
    const startDayOfWeek = startDateOfYear.getUTCDay() || 7;
    const dayOfWeek = 1; // Monday === 1
    const dayOfYear = week * 7 + dayOfWeek - (startDayOfWeek + 4);

    let date = formats["year"].data.parse(year);
    date = new Date(date.getTime() + dayOfYear * 24 * 60 * 60 * 1000);

    return date;
  };

  return format;

}
1279490
function(date, formatString, language){
        if (!date) return date;
        var array = formatString.match(u.date._formattingTokens), i, length,output='';
        var _date = u.date.getDateObj(date);
        if (!_date) return date;
        language = language || u.core.getLanguages();
        for (i = 0, length = array.length; i < length; i++) {
            if (u.date._formats[array[i]]) {
                output += u.date._formats[array[i]](_date, language);
            } else {
                output += array[i];
            }
        }
        return output;
    }
373546
public static String formatDuration(long millis) {
		StringBuilder sb = new StringBuilder();
		if(millis > DAY_MILLIS) {
			sb.append(millis / DAY_MILLIS);
			sb.append(" days, ");
			millis %= DAY_MILLIS;
		}
		if(millis > HOUR_MILLIS) {
			sb.append(millis / HOUR_MILLIS);
			sb.append(" hours, ");
			millis %= HOUR_MILLIS;
		}
		if(millis > MINUTE_MILLIS) {
			sb.append(millis / MINUTE_MILLIS);
			sb.append(" minutes, ");
			millis %= MINUTE_MILLIS;
		}
		if(millis > SECOND_MILLIS) {
			sb.append(millis / SECOND_MILLIS);
			sb.append(" seconds, ");
			millis %= SECOND_MILLIS;
		}
		sb.append(millis);
		sb.append(" milliseconds");
		return sb.toString();
	}
1116731
private String getDateString(Date value)
   {
      Calendar cal = DateHelper.popCalendar(value);
      int year = cal.get(Calendar.YEAR);
      int month = cal.get(Calendar.MONTH) + 1;
      int day = cal.get(Calendar.DAY_OF_MONTH);
      DateHelper.pushCalendar(cal);
      
      StringBuilder sb = new StringBuilder(8);
      sb.append(m_fourDigitFormat.format(year));
      sb.append(m_twoDigitFormat.format(month));
      sb.append(m_twoDigitFormat.format(day));

      return (sb.toString());
   }
1353052
function format(date, month, time) {
  return date.getFullYear() +
         zeroFill(date.getMonth() + 1) +
         (month ? zeroFill(date.getDate()) : '') +
         (time ?  'T' + zeroFill(date.getHours()) + zeroFill(date.getMinutes()) +
            zeroFill(date.getSeconds()) + 'Z' : '');
}
1275925
private String formatMonthDate(Date date) {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
            | DateUtils.FORMAT_NO_MONTH_DAY;

    // Save default Locale
    Locale defaultLocale = Locale.getDefault();

    // Set new default Locale, the reason to do that is DateUtils.formatDateTime uses
    // internally this method DateIntervalFormat.formatDateRange to format the date. And this
    // method uses the default locale.
    //
    // More details about the methods:
    // - DateUtils.formatDateTime: https://goo.gl/3YW52Q
    // - DateIntervalFormat.formatDateRange: https://goo.gl/RRmfK7
    Locale.setDefault(locale);

    String dateFormatted;
    if (displayAlwaysDigitNumbers
      && explicitlyNumericYearLocaleLanguages.contains(locale.getLanguage())) {
      StringBuilder sb = new StringBuilder();
      SimpleDateFormat sdfMonth = new SimpleDateFormat(getContext()
        .getString(R.string.month_only_name_format), locale);
      SimpleDateFormat sdfYear = new SimpleDateFormat(getContext()
        .getString(R.string.year_only_format), Locale.ENGLISH);
      dateFormatted = sb.append(sdfMonth.format(date.getTime())).append(" ")
        .append(sdfYear.format(date.getTime())).toString();
    } else {
      // Format date using the new Locale
      dateFormatted = DateUtils.formatDateRange(getContext(), monthFormatter,
        date.getTime(), date.getTime(), flags, timeZone.getID()).toString();
    }
    // Call setLength(0) on StringBuilder passed to the Formatter constructor to not accumulate
    // the results
    monthBuilder.setLength(0);

    // Restore default Locale to avoid generating any side effects
    Locale.setDefault(defaultLocale);

    return dateFormatted;
  }
536092
function timeElapsed(timeStamp) {
		var diff = _timeDifference(timeStamp);
		var yearStr = _generateTimeString(diff.year, "a year", "years");
		var monthStr = _generateTimeString(diff.month, "a month", "months");
		var dayStr = _generateTimeString(diff.day, "a day", "days");
		var hourStr = _generateTimeString(diff.hour, "an hour", "hours");
		var minuteStr = _generateTimeString(diff.minute, "a minute", "minutes");
		var disPlayStr = "";
		if(yearStr) {
			disPlayStr = diff.year > 0 ? yearStr : yearStr + monthStr;
		} else if(monthStr) {
			disPlayStr = diff.month > 0 ? monthStr : monthStr + dayStr;
		} else if(dayStr) {
			disPlayStr = diff.day > 0 ? dayStr : dayStr + hourStr;
		} else if(hourStr) {
			disPlayStr = diff.hour > 0 ? hourStr : hourStr + minuteStr;
		} else if(minuteStr) {
			disPlayStr = minuteStr;
		}
		return disPlayStr;	
	}
1282337
static public String getFormattedDays(long dt)
    {
        StringBuffer ret = new StringBuffer();

        long days = dt/86400000L;
        long millis = dt-(days*86400000L);
        if(days > 0)
        {
            ret.append(Long.toString(days));
            ret.append(" days ");
        }
        ret.append(getFormattedTime(millis, false));

        return ret.toString();
    }