(function($) { var extensionMethods = { getSmartDate: function(value, overidedDateFormat, overidedTimeFormat, overidedLocale){ var locale = "fr"; if (overidedLocale) { locale = overidedLocale; } else { try { locale = edContext().locale; } catch(e) {} } var dateFormat = "dd/mm/yy"; if (overidedDateFormat) { dateFormat = overidedDateFormat; } else { try { dateFormat = edContext().dateFormat; } catch(e) {} } var timeFormat = "hh:mm:ss"; if (overidedTimeFormat) { timeFormat = overidedTimeFormat; } else { try { timeFormat = edContext().timeFormat; } catch(e) {} } var daysInWeek = $.datepicker.regional[locale].dayNames; var shortMonthsInYear = $.datepicker.regional[locale].monthNamesShort; var longMonthsInYear = $.datepicker.regional[locale].monthNames; var labelToday = $.datepicker.regional[locale].labelToday; var labelAMomentAgo = $.datepicker.regional[locale].labelAMomentAgo; var labelMinute = $.datepicker.regional[locale].labelMinute; var labelMinutes = $.datepicker.regional[locale].labelMinutes; var labelSecond = $.datepicker.regional[locale].labelSecond; var labelSeconds = $.datepicker.regional[locale].labelSeconds; var labelAgo = $.datepicker.regional[locale].labelAgo; var labelHour = $.datepicker.regional[locale].labelHour; var labelHours = $.datepicker.regional[locale].labelHours; var labelYesterday = $.datepicker.regional[locale].labelYesterday; var labelAt = $.datepicker.regional[locale].labelAt; var labelDay = $.datepicker.regional[locale].labelDay; var labelDays = $.datepicker.regional[locale].labelDays; var labelLastMonth = $.datepicker.regional[locale].labelLastMonth; var labelLast = $.datepicker.regional[locale].labelLast; var labelMonths = $.datepicker.regional[locale].labelMonths; var labelYears = $.datepicker.regional[locale].labelYears; var labelLastYear = $.datepicker.regional[locale].labelLastYear; var labelOClock = $.datepicker.regional[locale].labelOClock; var labelIn = $.datepicker.regional[locale].labelIn; var labelNext = $.datepicker.regional[locale].labelNext; var labelTomorrow = $.datepicker.regional[locale].labelTomorrow; var labelInAFewMoment = $.datepicker.regional[locale].labelInAFewMoment; var labelNextMonth = $.datepicker.regional[locale].labelNextMonth; var labelNextYear = $.datepicker.regional[locale].labelNextYear; //value is a string //check what need to be parsed //this could be just a date, just a time, both of them //if time, check if seconds are presents. If not add them var isTime = false; var isDate = false; var isampm = false; var completeValue = value; var splittedValue = value.split(" "); var parsedDate; var parsedDateTime; var parsedTime; var parsedAmPm = ""; if (value.indexOf("PM") > -1) { parsedAmPm = "PM"; isampm = true; } else { if (value.indexOf("AM") > -1) { parsedAmPm = "AM"; isampm = true; } } var withoutSecondsTimeFormat = timeFormat.replace(":ss", "").replace(":s", ""); for (var i=0; i diffToTomorrow) { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelTomorrow + " " + completeTime; } else { if (isTime) { return labelIn + " " + diffInHours + " " + labelHours; } else { return labelToday; } } } } else { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelTomorrow + " " + completeTime; } } else { var diffInMonth = $.datepicker.DateDiff.inMonths(nowDate, currentDate); if (diffInDays == 1) { var tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); var tomorrowMidnight = new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate()); var diffToTomorrow = $.datepicker.DateDiff.inHours(nowDate, tomorrowMidnight); if (diffInHours < diffToTomorrow + 24) { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelTomorrow + " " + completeTime; } else { return daysInWeek[currentDate.getDay()] + " " + labelNext + " " + completeTime; } } else { if (diffInMonth == 0) { if (diffInDays < 7) { if (locale == "en") { return labelNext + " " + daysInWeek[currentDate.getDay()] + " " + completeTime; } else { return daysInWeek[currentDate.getDay()] + " " + labelNext + " " + completeTime; } } else { return labelIn + " " + diffInDays + " " + labelDays; } } else { if (diffInMonth == 1) { return labelNextMonth; } else { var diffInYears = $.datepicker.DateDiff.inYears(nowDate, currentDate); if (diffInYears == 0) { if (diffInMonth < 12) { if (locale == "en") { return labelNext + " " + longMonthsInYear[currentDate.getMonth()]; } else { return longMonthsInYear[currentDate.getMonth()] + " " + labelNext; } } else { return labelIn + " " + diffInMonth + " " + labelMonths; } } else { if (diffInYears == 1) { return labelNextYear; } else { return labelIn + " " + diffInYears + " " + labelYears; } } } } } } } } } else { //it's a past date if (diffInSeconds < 60) { if (isTime) { return labelAMomentAgo; } else { return labelToday; } } else { var diffInMinutes = $.datepicker.DateDiff.inMinutes(currentDate, nowDate); if (diffInMinutes < 60) { if (isTime) { if (diffInMinutes == 1) { if (locale == "en") { return diffInMinutes + " " + labelMinute + " " + labelAgo; } else { return labelAgo + " " + diffInMinutes + " " + labelMinute; } } else { if (locale == "en") { return diffInMinutes + " " + labelMinutes + " " + labelAgo; } else { return labelAgo + " " + diffInMinutes + " " + labelMinutes; } } } else { return labelToday; } } else { var diffInDays = $.datepicker.DateDiff.inDays(currentDate, nowDate); var diffInHours = $.datepicker.DateDiff.inHours(currentDate, nowDate); if (diffInHours < 24) { if (diffInDays == 0) { if (diffInHours == 1) { if (isTime) { if (locale == "en") { return diffInHours + " " + labelHour + " " + labelAgo; } else { return labelAgo + " " + diffInHours + " " + labelHours; } } else { return labelToday; } } else { var midnightDate = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate()); var diffSinceMidnight = $.datepicker.DateDiff.inHours(midnightDate, nowDate); if (diffInHours > diffSinceMidnight) { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelYesterday + " " + completeTime; } else { if (isTime) { if (locale == "en") { return diffInHours + " " + labelHours + " " + labelAgo; } else { return labelAgo + " " + diffInHours + " " + labelHours; } } else { return labelToday; } } } } else { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelYesterday + " " + completeTime; } } else { var diffInMonth = $.datepicker.DateDiff.inMonths(currentDate, nowDate); if (diffInDays == 1) { //return labelYesterday + " " + labelAt + " " + time.hour + " " + labelOClock; return labelYesterday + " " + completeTime; } else { if (diffInMonth == 0) { if (diffInDays < 7) { //return daysInWeek[currentDate.getDay()] + " " + labelAt + " " + time.hour + " " + labelOClock; if (locale == "en") { return labelLast + " " + daysInWeek[currentDate.getDay()] + " " + completeTime; } else { return daysInWeek[currentDate.getDay()] + " " + labelLast + " " + completeTime; } } else { if (locale == "en") { return diffInDays + " " + labelDays + " " + labelAgo; } else { return labelAgo + " " + diffInDays + " " + labelDays; } } } else { if (diffInMonth == 1) { return labelLastMonth; } else { var diffInYears = $.datepicker.DateDiff.inYears(currentDate, nowDate); if (diffInYears == 0) { if (diffInMonth < 12) { if (locale == "en") { return labelLast + " " + longMonthsInYear[currentDate.getMonth()]; } else { return longMonthsInYear[currentDate.getMonth()] + " " + labelLast; } } else { if (locale == "en") { return diffInMonth + " " + labelMonths + " " + labelAgo; } else { return labelAgo + " " + diffInMonth + " " + labelMonths; } } } else { if (diffInYears == 1) { return labelLastYear; } else { if (locale == "en") { return diffInYears + " " + labelYears + " " + labelAgo; } else { return labelAgo + " " + diffInYears + " " + labelYears; } } } } } } } } } } } } }; $.extend(true, $.datepicker, extensionMethods); })(jQuery); (function($) { var extensionMethods = { DateDiff : { inSeconds: function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(1000)); }, inMinutes: function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(60*1000)); }, inHours: function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(3600*1000)); }, inDays: function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(24*3600*1000)); }, inWeeks: function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(24*3600*1000*7)); }, inMonths: function(d1, d2) { var d1Y = d1.getFullYear(); var d2Y = d2.getFullYear(); var d1M = d1.getMonth(); var d2M = d2.getMonth(); return (d2M+12*d2Y)-(d1M+12*d1Y); }, inYears: function(d1, d2) { return d2.getFullYear()-d1.getFullYear(); } } }; $.extend(true, $.datepicker, extensionMethods); })(jQuery);