Sha256: cbedb93eccd0f80c0689502eae90f9ed8dcc08dccd0c7ef93c522bac068a2a0f

Contents?: true

Size: 1.1 KB

Versions: 126

Compression:

Stored size: 1.1 KB

Contents

// American Format: 12/31/2000 5:00 pm
// Thanks, Wes Hays
Date.prototype.toFormattedString = function(include_time){
  str = Date.padded2(this.getMonth() + 1) + '/' +Date.padded2(this.getDate()) + '/' + this.getFullYear();

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

Date.parseFormattedString = function (string) {
  // Test these with and without the time
  // 11/11/1111 12pm
  // 11/11/1111 1pm
  // 1/11/1111 10:10pm
  // 11/1/1111 01pm
  // 1/1/1111 01:11pm
  // 1/1/1111 1:11pm
  var regexp = "(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *([0-9]{1,2}(:[0-9]{2})? *(am|pm))?";
  var d = string.match(new RegExp(regexp, "i"));
  if (d==null) {
    return Date.parse(string); // Give javascript a chance to parse it.
  }

  mdy = d[1].split('/');
  hrs = 0;
  mts = 0;
  if(d[3] != null) {
    hrs = parseInt(d[3].split('')[0], 10);
    if(d[5].toLowerCase() == 'pm') { hrs += 12; } // Add 12 more to hrs
    mts = d[4].split(':')[1];
  }
  
  return new Date(mdy[2], parseInt(mdy[0], 10)-1, mdy[1], hrs, mts, 0);
}

Version data entries

126 entries across 92 versions & 19 rubygems

Version Path
spree-0.9.2 public/javascripts/calendar_date_select/format_american.js
spree-0.9.1 public/javascripts/calendar_date_select/format_american.js
webroar-0.2.2 src/admin_panel/public/javascripts/calendar_date_select/format_american.js
spree-0.9.0 public/javascripts/calendar_date_select/format_american.js
spree-0.8.4 public/javascripts/calendar_date_select/format_american.js
spree-0.8.5 public/javascripts/calendar_date_select/format_american.js
calendar_date_select-1.15 public/javascripts/calendar_date_select/format_american.js
calendar_date_select-1.12 public/javascripts/calendar_date_select/format_american.js
calendar_date_select-1.11.1 public/javascripts/calendar_date_select/format_american.js
calendar_date_select-1.13 public/javascripts/calendar_date_select/format_american.js
calendar_date_select-1.14 public/javascripts/calendar_date_select/format_american.js
railscart-0.0.1 starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
railscart-0.0.2 starter_app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
railscart-0.0.3 starter_app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
railscart-0.0.4 starter_app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
spree-0.0.6 starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
spree-0.0.5 starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
spree-0.0.9 public/plugin_assets/calendar_date_select/javascripts/calendar_date_select/format_american.js
spree-0.0.7 starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js
spree-0.0.8 starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js