nebukad

function_js

Oct 2nd, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created on : Jul 06, 2017, 10:14:00 AM
  3.  * Author     : Muhammad Ircham
  4.  */
  5. function number_format (number, decimals, decPoint, thousandsSep) {
  6.     // eslint-disable-line camelcase
  7.     //  discuss at: http://locutus.io/php/number_format/
  8.     // original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  9.     // improved by: Kevin van Zonneveld (http://kvz.io)
  10.     // improved by: davook
  11.     // improved by: Brett Zamir (http://brett-zamir.me)
  12.     // improved by: Brett Zamir (http://brett-zamir.me)
  13.     // improved by: Theriault (https://github.com/Theriault)
  14.     // improved by: Kevin van Zonneveld (http://kvz.io)
  15.     // bugfixed by: Michael White (http://getsprink.com)
  16.     // bugfixed by: Benjamin Lupton
  17.     // bugfixed by: Allan Jensen (http://www.winternet.no)
  18.     // bugfixed by: Howard Yeend
  19.     // bugfixed by: Diogo Resende
  20.     // bugfixed by: Rival
  21.     // bugfixed by: Brett Zamir (http://brett-zamir.me)
  22.     //  revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  23.     //  revised by: Luke Smith (http://lucassmith.name)
  24.     //    input by: Kheang Hok Chin (http://www.distantia.ca/)
  25.     //    input by: Jay Klehr
  26.     //    input by: Amir Habibi (http://www.residence-mixte.com/)
  27.     //    input by: Amirouche
  28.     //   example 1: number_format(1234.56)
  29.     //   returns 1: '1,235'
  30.     //   example 2: number_format(1234.56, 2, ',', ' ')
  31.     //   returns 2: '1 234,56'
  32.     //   example 3: number_format(1234.5678, 2, '.', '')
  33.     //   returns 3: '1234.57'
  34.     //   example 4: number_format(67, 2, ',', '.')
  35.     //   returns 4: '67,00'
  36.     //   example 5: number_format(1000)
  37.     //   returns 5: '1,000'
  38.     //   example 6: number_format(67.311, 2)
  39.     //   returns 6: '67.31'
  40.     //   example 7: number_format(1000.55, 1)
  41.     //   returns 7: '1,000.6'
  42.     //   example 8: number_format(67000, 5, ',', '.')
  43.     //   returns 8: '67.000,00000'
  44.     //   example 9: number_format(0.9, 0)
  45.     //   returns 9: '1'
  46.     //  example 10: number_format('1.20', 2)
  47.     //  returns 10: '1.20'
  48.     //  example 11: number_format('1.20', 4)
  49.     //  returns 11: '1.2000'
  50.     //  example 12: number_format('1.2000', 3)
  51.     //  returns 12: '1.200'
  52.     //  example 13: number_format('1 000,50', 2, '.', ' ')
  53.     //  returns 13: '100 050.00'
  54.     //  example 14: number_format(1e-8, 8, '.', '')
  55.     //  returns 14: '0.00000001'
  56.     number = (number + '').replace(/[^0-9+\-Ee.]/g, '')
  57.     var n = !isFinite(+number) ? 0 : +number
  58.     var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
  59.     var sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep
  60.     var dec = (typeof decPoint === 'undefined') ? '.' : decPoint
  61.     var s = ''
  62.     var toFixedFix = function (n, prec) {
  63.         var k = Math.pow(10, prec)
  64.         return '' + (Math.round(n * k) / k)
  65.                 .toFixed(prec)
  66.     }
  67.     // @todo: for IE parseFloat(0.55).toFixed(0) = 0;
  68.     s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.')
  69.     if (s[0].length > 3) {
  70.         s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep)
  71.     }
  72.     if ((s[1] || '').length < prec) {
  73.         s[1] = s[1] || ''
  74.         s[1] += new Array(prec - s[1].length + 1).join('0')
  75.     }
  76.     return s.join(dec)
  77. }
  78.  
  79. function createCookie(name,value,days) {
  80.     var expires = "";
  81.     if (days) {
  82.         var date = new Date();
  83.         date.setTime(date.getTime() + (days*24*60*60*1000));
  84.         expires = "; expires=" + date.toUTCString();
  85.     }
  86.     document.cookie = name + "=" + value + expires + "; path=/";
  87. }
  88.  
  89. function readCookie(name) {
  90.     var nameEQ = name + "=";
  91.     var ca = document.cookie.split(';');
  92.     for(var i=0;i < ca.length;i++) {
  93.         var c = ca[i];
  94.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  95.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  96.     }
  97.     return null;
  98. }
  99.  
  100. function eraseCookie(name) {
  101.     createCookie(name,"",-1);
  102. }
  103.  
  104. function clean_input(_this, target, max) {
  105.     var $this = $(_this),
  106.         val = $this.val(),
  107.         remaining = max - val.length;
  108.  
  109.     var error_max = $('.error-notes-max');
  110.     var error_char = $('.error-notes-char');
  111.  
  112.     var specialChars = "<>$%!#^&*[]{}|'\"\\~`";
  113.     var check = function(string){
  114.         for(i = 0; i < specialChars.length;i++){
  115.             if(string.indexOf(specialChars[i]) > -1){
  116.                 return true
  117.             }
  118.         }
  119.         return false;
  120.     };
  121.  
  122.     if(check(val) === true){
  123.         // clean containing string
  124.         var cek = val.replace(/[<>$%!#^&*[\]{}|'"\\~`]/g, '');
  125.         $this.val(cek.substring(0, max));
  126.         var newval = $this.val();
  127.         remaining = max - newval.length;
  128.         // alert('Special character akan otomatis dihapus');
  129.         if(error_char.length === 0) $this.parent().append('<p class="error-notes-char" style="color: red;">Special character akan otomatis dihapus</p>');
  130.     }
  131.  
  132.     if(remaining < 0){
  133.         var newvals = val.substring(0, max)
  134.         $this.val(newvals);
  135.         remaining = max - newvals.length;
  136.         // alert('Huruf akan dipotong sesuai batas '+ max +' huruf');
  137.         if(error_max.length === 0) $this.parent().append('<p class="error-notes-max" style="color: red;">Huruf akan dipotong sesuai batas '+ max +' huruf</p>');
  138.     }
  139.  
  140.     if(error_max.length > 0) {
  141.         setTimeout(function(){
  142.             error_max.hide('slow').remove();
  143.         }, 2000);
  144.     }
  145.  
  146.     if(error_char.length > 0) {
  147.         setTimeout(function(){
  148.             error_char.hide('slow').remove();
  149.         }, 2000);
  150.     }
  151.     $(target).html(remaining);
  152. }
  153.  
  154. function check_special(string){
  155.     var specialChars = "<>@!#$%^&*()[]{}|'\"\\/~`";
  156.  
  157.     for(i = 0; i < specialChars.length;i++){
  158.         if(string.indexOf(specialChars[i]) > -1){
  159.             return true
  160.         }
  161.     }
  162.     return false;
  163. }
  164.  
  165. function replace_special(string){
  166.     return string.replace(/[<>@!#$%^&*()[\]{}|'"\/\\~`]/g, '');
  167. }
  168.  
  169. function limit_input(_this, max) {
  170.     var $this = $(_this),
  171.         string = $this.val(),
  172.         slice = string.substring(0, max);
  173.     $this.val(slice);
  174. }
  175.  
  176. // https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript
  177. function capitalize(string) {
  178.     return string[0].toUpperCase() + string.slice(1);
  179. }
  180.  
  181. /**
  182.  * @source http://phpjs.org/functions/date/
  183.  * @param {string} format
  184.  * @param {string} timestamp
  185.  * @returns {string}
  186.  */
  187. function dateFormat(format, timestamp) {
  188.     var that = this;
  189.     var jsdate, f;
  190.     var txt_words = [
  191.         'Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu',
  192.         'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
  193.         'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
  194.     ];
  195.     var formatChr = /\\?(.?)/gi;
  196.     var formatChrCb = function (t, s) {
  197.         return f[t] ? f[t]() : s;
  198.     };
  199.     var _pad = function (n, c) {
  200.         n = String(n);
  201.         while (n.length < c) {
  202.             n = '0' + n;
  203.         }
  204.         return n;
  205.     };
  206.     f = {
  207.         // Day
  208.         d: function () { // Day of month w/leading 0; 01..31
  209.             return _pad(f.j(), 2);
  210.         },
  211.         D: function () { // Shorthand day name; Mon...Sun
  212.             return f.l()
  213.                 .slice(0, 3);
  214.         },
  215.         j: function () { // Day of month; 1..31
  216.             return jsdate.getDate();
  217.         },
  218.         l: function () { // Full day name; Monday...Sunday
  219.             return txt_words[f.w()] + '';
  220.         },
  221.         N: function () { // ISO-8601 day of week; 1[Mon]..7[Sun]
  222.             return f.w() || 7;
  223.         },
  224.         S: function () { // Ordinal suffix for day of month; st, nd, rd, th
  225.             var j = f.j();
  226.             var i = j % 10;
  227.             if (i <= 3 && parseInt((j % 100) / 10, 10) == 1) {
  228.                 i = 0;
  229.             }
  230.             return ['st', 'nd', 'rd'][i - 1] || 'th';
  231.         },
  232.         w: function () { // Day of week; 0[Sun]..6[Sat]
  233.             return jsdate.getDay();
  234.         },
  235.         z: function () { // Day of year; 0..365
  236.             var a = new Date(f.Y(), f.n() - 1, f.j());
  237.             var b = new Date(f.Y(), 0, 1);
  238.             return Math.round((a - b) / 864e5);
  239.         },
  240.         // Week
  241.         W: function () { // ISO-8601 week number
  242.             var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3);
  243.             var b = new Date(a.getFullYear(), 0, 4);
  244.             return _pad(1 + Math.round((a - b) / 864e5 / 7), 2);
  245.         },
  246.         // Month
  247.         F: function () { // Full month name; January...December
  248.             return txt_words[6 + f.n()];
  249.         },
  250.         m: function () { // Month w/leading 0; 01...12
  251.             return _pad(f.n(), 2);
  252.         },
  253.         M: function () { // Shorthand month name; Jan...Dec
  254.             return f.F()
  255.                 .slice(0, 3);
  256.         },
  257.         n: function () { // Month; 1...12
  258.             return jsdate.getMonth() + 1;
  259.         },
  260.         t: function () { // Days in month; 28...31
  261.             return (new Date(f.Y(), f.n(), 0))
  262.                 .getDate();
  263.         },
  264.         // Year
  265.         L: function () { // Is leap year?; 0 or 1
  266.             var j = f.Y();
  267.             return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0;
  268.         },
  269.         o: function () { // ISO-8601 year
  270.             var n = f.n();
  271.             var W = f.W();
  272.             var Y = f.Y();
  273.             return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0);
  274.         },
  275.         Y: function () { // Full year; e.g. 1980...2010
  276.             return jsdate.getFullYear();
  277.         },
  278.         y: function () { // Last two digits of year; 00...99
  279.             return f.Y()
  280.                 .toString()
  281.                 .slice(-2);
  282.         },
  283.         // Time
  284.         a: function () { // am or pm
  285.             return jsdate.getHours() > 11 ? 'pm' : 'am';
  286.         },
  287.         A: function () { // AM or PM
  288.             return f.a()
  289.                 .toUpperCase();
  290.         },
  291.         B: function () { // Swatch Internet time; 000..999
  292.             var H = jsdate.getUTCHours() * 36e2;
  293.             // Hours
  294.             var i = jsdate.getUTCMinutes() * 60;
  295.             // Minutes
  296.             var s = jsdate.getUTCSeconds(); // Seconds
  297.             return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
  298.         },
  299.         g: function () { // 12-Hours; 1..12
  300.             return f.G() % 12 || 12;
  301.         },
  302.         G: function () { // 24-Hours; 0..23
  303.             return jsdate.getHours();
  304.         },
  305.         h: function () { // 12-Hours w/leading 0; 01..12
  306.             return _pad(f.g(), 2);
  307.         },
  308.         H: function () { // 24-Hours w/leading 0; 00..23
  309.             return _pad(f.G(), 2);
  310.         },
  311.         i: function () { // Minutes w/leading 0; 00..59
  312.             return _pad(jsdate.getMinutes(), 2);
  313.         },
  314.         s: function () { // Seconds w/leading 0; 00..59
  315.             return _pad(jsdate.getSeconds(), 2);
  316.         },
  317.         u: function () { // Microseconds; 000000-999000
  318.             return _pad(jsdate.getMilliseconds() * 1000, 6);
  319.         },
  320.         // Timezone
  321.         e: function () {
  322.             throw 'Not supported (see source code of date() for timezone on how to add support)';
  323.         },
  324.         I: function () { // DST observed?; 0 or 1
  325.             // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
  326.             // If they are not equal, then DST is observed.
  327.             var a = new Date(f.Y(), 0);
  328.             // Jan 1
  329.             var c = Date.UTC(f.Y(), 0);
  330.             // Jan 1 UTC
  331.             var b = new Date(f.Y(), 6);
  332.             // Jul 1
  333.             var d = Date.UTC(f.Y(), 6); // Jul 1 UTC
  334.             return ((a - c) !== (b - d)) ? 1 : 0;
  335.         },
  336.         O: function () { // Difference to GMT in hour format; e.g. +0200
  337.             var tzo = jsdate.getTimezoneOffset();
  338.             var a = Math.abs(tzo);
  339.             return (tzo > 0 ? '-' : '+') + _pad(Math.floor(a / 60) * 100 + a % 60, 4);
  340.         },
  341.         P: function () { // Difference to GMT w/colon; e.g. +02:00
  342.             var O = f.O();
  343.             return (O.substr(0, 3) + ':' + O.substr(3, 2));
  344.         },
  345.         T: function () {
  346.             return 'UTC';
  347.         },
  348.         Z: function () { // Timezone offset in seconds (-43200...50400)
  349.             return -jsdate.getTimezoneOffset() * 60;
  350.         },
  351.         // Full Date/Time
  352.         c: function () { // ISO-8601 date.\
  353.             return 'Y-m-d\\TH:i:sP'.replace(formatChr, formatChrCb);
  354.         },
  355.         r: function () { // RFC 2822
  356.             return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);
  357.         },
  358.         U: function () { // Seconds since UNIX epoch
  359.             return jsdate / 1000 | 0;
  360.         }
  361.     };
  362.     this.date = function (format, timestamp) {
  363.         that = this;
  364.         jsdate = (timestamp === undefined ? new Date() : // Not provided
  365.                 (timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
  366.                     new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
  367.         );
  368.         return format.replace(formatChr, formatChrCb);
  369.     };
  370.     return this.date(format, timestamp);
  371. }
  372.  
  373. /**
  374.  * @source http://phpjs.org/functions/strtotime/
  375.  * @param {string} text
  376.  * @param {string} now
  377.  * @returns {Number|Date|Boolean}
  378.  */
  379. function strtotime(text, now) {
  380.     var parsed, match, today, year, date, days, ranges, len, times, regex, i, fail = false;
  381.  
  382.     if (!text) {
  383.         return fail;
  384.     }
  385.  
  386.     // Unecessary spaces
  387.     text = text.replace(/^\s+|\s+$/g, '')
  388.         .replace(/\s{2,}/g, ' ')
  389.         .replace(/[\t\r\n]/g, '')
  390.         .toLowerCase();
  391.  
  392.     match = text.match(
  393.         /^(\d{1,4})([\-\.\/\:])(\d{1,2})([\-\.\/\:])(\d{1,4})(?:\s(\d{1,2}):(\d{2})?:?(\d{2})?)?(?:\s([A-Z]+)?)?$/);
  394.  
  395.     if (match && match[2] === match[4]) {
  396.         if (match[1] > 1901) {
  397.             switch (match[2]) {
  398.                 case '-':
  399.                 { // YYYY-M-D
  400.                     if (match[3] > 12 || match[5] > 31) {
  401.                         return fail;
  402.                     }
  403.  
  404.                     return new Date(match[1], parseInt(match[3], 10) - 1, match[5],
  405.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  406.                 }
  407.                 case '.':
  408.                 { // YYYY.M.D is not parsed by strtotime()
  409.                     return fail;
  410.                 }
  411.                 case '/':
  412.                 { // YYYY/M/D
  413.                     if (match[3] > 12 || match[5] > 31) {
  414.                         return fail;
  415.                     }
  416.  
  417.                     return new Date(match[1], parseInt(match[3], 10) - 1, match[5],
  418.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  419.                 }
  420.             }
  421.         } else if (match[5] > 1901) {
  422.             switch (match[2]) {
  423.                 case '-':
  424.                 { // D-M-YYYY
  425.                     if (match[3] > 12 || match[1] > 31) {
  426.                         return fail;
  427.                     }
  428.  
  429.                     return new Date(match[5], parseInt(match[3], 10) - 1, match[1],
  430.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  431.                 }
  432.                 case '.':
  433.                 { // D.M.YYYY
  434.                     if (match[3] > 12 || match[1] > 31) {
  435.                         return fail;
  436.                     }
  437.  
  438.                     return new Date(match[5], parseInt(match[3], 10) - 1, match[1],
  439.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  440.                 }
  441.                 case '/':
  442.                 { // M/D/YYYY
  443.                     if (match[1] > 12 || match[3] > 31) {
  444.                         return fail;
  445.                     }
  446.  
  447.                     return new Date(match[5], parseInt(match[1], 10) - 1, match[3],
  448.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  449.                 }
  450.             }
  451.         } else {
  452.             switch (match[2]) {
  453.                 case '-':
  454.                 { // YY-M-D
  455.                     if (match[3] > 12 || match[5] > 31 || (match[1] < 70 && match[1] > 38)) {
  456.                         return fail;
  457.                     }
  458.  
  459.                     year = match[1] >= 0 && match[1] <= 38 ? +match[1] + 2000 : match[1];
  460.                     return new Date(year, parseInt(match[3], 10) - 1, match[5],
  461.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  462.                 }
  463.                 case '.':
  464.                 { // D.M.YY or H.MM.SS
  465.                     if (match[5] >= 70) { // D.M.YY
  466.                         if (match[3] > 12 || match[1] > 31) {
  467.                             return fail;
  468.                         }
  469.  
  470.                         return new Date(match[5], parseInt(match[3], 10) - 1, match[1],
  471.                                 match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  472.                     }
  473.                     if (match[5] < 60 && !match[6]) { // H.MM.SS
  474.                         if (match[1] > 23 || match[3] > 59) {
  475.                             return fail;
  476.                         }
  477.  
  478.                         today = new Date();
  479.                         return new Date(today.getFullYear(), today.getMonth(), today.getDate(),
  480.                                 match[1] || 0, match[3] || 0, match[5] || 0, match[9] || 0) / 1000;
  481.                     }
  482.  
  483.                     return fail; // invalid format, cannot be parsed
  484.                 }
  485.                 case '/':
  486.                 { // M/D/YY
  487.                     if (match[1] > 12 || match[3] > 31 || (match[5] < 70 && match[5] > 38)) {
  488.                         return fail;
  489.                     }
  490.  
  491.                     year = match[5] >= 0 && match[5] <= 38 ? +match[5] + 2000 : match[5];
  492.                     return new Date(year, parseInt(match[1], 10) - 1, match[3],
  493.                             match[6] || 0, match[7] || 0, match[8] || 0, match[9] || 0) / 1000;
  494.                 }
  495.                 case ':':
  496.                 { // HH:MM:SS
  497.                     if (match[1] > 23 || match[3] > 59 || match[5] > 59) {
  498.                         return fail;
  499.                     }
  500.  
  501.                     today = new Date();
  502.                     return new Date(today.getFullYear(), today.getMonth(), today.getDate(),
  503.                             match[1] || 0, match[3] || 0, match[5] || 0) / 1000;
  504.                 }
  505.             }
  506.         }
  507.     }
  508.  
  509.     // other formats and "now" should be parsed by Date.parse()
  510.     if (text === 'now') {
  511.         return now === null || isNaN(now) ? new Date()
  512.                 .getTime() / 1000 | 0 : now | 0;
  513.     }
  514.     if (!isNaN(parsed = Date.parse(text))) {
  515.         return parsed / 1000 | 0;
  516.     }
  517.  
  518.     date = now ? new Date(now * 1000) : new Date();
  519.     days = {
  520.         'sun': 0,
  521.         'mon': 1,
  522.         'tue': 2,
  523.         'wed': 3,
  524.         'thu': 4,
  525.         'fri': 5,
  526.         'sat': 6
  527.     };
  528.     ranges = {
  529.         'yea': 'FullYear',
  530.         'mon': 'Month',
  531.         'day': 'Date',
  532.         'hou': 'Hours',
  533.         'min': 'Minutes',
  534.         'sec': 'Seconds'
  535.     };
  536.  
  537.     function lastNext(type, range, modifier) {
  538.         var diff, day = days[range];
  539.  
  540.         if (typeof day !== 'undefined') {
  541.             diff = day - date.getDay();
  542.  
  543.             if (diff === 0) {
  544.                 diff = 7 * modifier;
  545.             } else if (diff > 0 && type === 'last') {
  546.                 diff -= 7;
  547.             } else if (diff < 0 && type === 'next') {
  548.                 diff += 7;
  549.             }
  550.  
  551.             date.setDate(date.getDate() + diff);
  552.         }
  553.     }
  554.  
  555.     function process(val) {
  556.         var splt = val.split(' '), // Todo: Reconcile this with regex using \s, taking into account browser issues with split and regexes
  557.             type = splt[0],
  558.             range = splt[1].substring(0, 3),
  559.             typeIsNumber = /\d+/.test(type),
  560.             ago = splt[2] === 'ago',
  561.             num = (type === 'last' ? -1 : 1) * (ago ? -1 : 1);
  562.  
  563.         if (typeIsNumber) {
  564.             num *= parseInt(type, 10);
  565.         }
  566.  
  567.         if (ranges.hasOwnProperty(range) && !splt[1].match(/^mon(day|\.)?$/i)) {
  568.             return date['set' + ranges[range]](date['get' + ranges[range]]() + num);
  569.         }
  570.  
  571.         if (range === 'wee') {
  572.             return date.setDate(date.getDate() + (num * 7));
  573.         }
  574.  
  575.         if (type === 'next' || type === 'last') {
  576.             lastNext(type, range, num);
  577.         } else if (!typeIsNumber) {
  578.             return false;
  579.         }
  580.  
  581.         return true;
  582.     }
  583.  
  584.     times = '(years?|months?|weeks?|days?|hours?|minutes?|min|seconds?|sec' +
  585.         '|sunday|sun\\.?|monday|mon\\.?|tuesday|tue\\.?|wednesday|wed\\.?' +
  586.         '|thursday|thu\\.?|friday|fri\\.?|saturday|sat\\.?)';
  587.     regex = '([+-]?\\d+\\s' + times + '|' + '(last|next)\\s' + times + ')(\\sago)?';
  588.  
  589.     match = text.match(new RegExp(regex, 'gi'));
  590.     if (!match) {
  591.         return fail;
  592.     }
  593.  
  594.     for (i = 0, len = match.length; i < len; i++) {
  595.         if (!process(match[i])) {
  596.             return fail;
  597.         }
  598.     }
  599.  
  600.     // ECMAScript 5 only
  601.     // if (!match.every(process))
  602.     //    return false;
  603.  
  604.     return (date.getTime() / 1000);
  605. }
Advertisement
Add Comment
Please, Sign In to add comment