Sha256: 57007128ce7e70283f0d498d3f0ed4b967beccf3c9209f5c747cdb383fbae18c

Contents?: true

Size: 1.24 KB

Versions: 76

Compression:

Stored size: 1.24 KB

Contents

Date.prototype.toFormattedString = function(include_time){
  str = this.getFullYear() + "-" + Date.padded2(this.getMonth() + 1) + "-" +Date.padded2(this.getDate()); 

if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() + " " + this.getAMPM() }
return str;
}

Date.parseFormattedString = function (string) {
  var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
      "( ([0-9]{1,2}):([0-9]{2})? *(pm|am)" +
      "?)?)?)?";
  var d = string.match(new RegExp(regexp, "i"));
  if (d==null) return Date.parse(string); // at least give javascript a crack at it.
  var offset = 0;
  var date = new Date(d[1], 0, 1);
  if (d[3]) { date.setMonth(d[3] - 1); }
  if (d[5]) { date.setDate(d[5]); }
  if (d[7]) {
    hours = parseInt(d[7], 10);
    offset=0;
    if (d[9]) {
        is_pm = (d[9].toLowerCase()=="pm");
        if (is_pm && hours <= 11) hours+=12;
        if (!is_pm && hours == 12) hours=0;
    }
    date.setHours(hours); 
  }
  if (d[8]) { date.setMinutes(d[8]); }
  if (d[10]) { date.setSeconds(d[10]); }
  if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
  if (d[14]) {
      offset = (Number(d[16]) * 60) + Number(d[17]);
      offset *= ((d[15] == '-') ? 1 : -1);
  }

  return date;
}

Version data entries

76 entries across 54 versions & 12 rubygems

Version Path
DavidWhite-calendar_date_select-1.15.5 public/javascripts/calendar_date_select/format_hyphen_ampm.js
DavidWhite-calendar_date_select-1.15.6 public/javascripts/calendar_date_select/format_hyphen_ampm.js
atd-calendar_date_select-1.11.20090216 public/javascripts/calendar_date_select/format_hyphen_ampm.js
atd-calendar_date_select-1.15 public/javascripts/calendar_date_select/format_hyphen_ampm.js
batasrki-calendar_date_select-1.13.3 public/javascripts/calendar_date_select/format_hyphen_ampm.js
kikito-calendar_date_select-1.0.1 public/javascripts/calendar_date_select/format_hyphen_ampm.js
kikito-calendar_date_select-1.0.2 public/javascripts/calendar_date_select/format_hyphen_ampm.js
calendar_date_select-2.0.0 app/assets/javascripts/calendar_date_select/format_hyphen_ampm.js
calendar_date_select_rails3-1.16.2 public/javascripts/calendar_date_select/format_hyphen_ampm.js
calendar_date_select-1.16.4 public/javascripts/calendar_date_select/format_hyphen_ampm.js
fat_free_crm-0.11.3 vendor/assets/javascripts/calendar_date_select/format_hyphen_ampm.js
fat_free_crm-0.11.2 vendor/assets/javascripts/calendar_date_select/format_hyphen_ampm.js
fat_free_crm-0.11.1 vendor/assets/javascripts/calendar_date_select/format_hyphen_ampm.js
fat_free_crm-0.11.0 vendor/assets/javascripts/calendar_date_select/format_hyphen_ampm.js
webroar-0.7.0 src/admin_panel/public/javascripts/calendar_date_select/format_hyphen_ampm.js
webroar-0.7.0 src/admin_panel/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_hyphen_ampm.js
webroar-0.6.1 src/admin_panel/public/javascripts/calendar_date_select/format_hyphen_ampm.js
calendar_date_select-1.16.3 public/javascripts/calendar_date_select/format_hyphen_ampm.js
branston-0.6.6 lib/branston/public/javascripts/calendar_date_select/format_hyphen_ampm.js
branston-0.6.6 lib/branston/vendor/plugins/calendar_date_select-1.15/public/javascripts/calendar_date_select/format_hyphen_ampm.js