Basis of rails-driven app for local business
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

27 lines
1.2 KiB

  1. // DB No Seconds Format: 2007-12-05 12:00
  2. Date.padded2 = function(hour) { padded2 = hour.toString(); if ((parseInt(hour) < 10) || (parseInt(hour) == null)) padded2="0" + padded2; return padded2; }
  3. Date.prototype.getAMPMHour = function() { hour=Date.padded2(this.getHours()); return (hour == null) ? 00 : (hour > 24 ? hour - 24 : hour ) }
  4. Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "" : ""; }
  5. Date.prototype.toFormattedString = function(include_time){
  6. str = this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + Date.padded2(this.getDate());
  7. if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() }
  8. return str;
  9. }
  10. Date.parseFormattedString = function (string) {
  11. var regexp = '([0-9]{4})-(([0-9]{1,2})-(([0-9]{1,2})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
  12. var d = string.match(new RegExp(regexp, "i"));
  13. if (d==null) return Date.parse(string); // at least give javascript a crack at it.
  14. var offset = 0;
  15. var date = new Date(d[1], 0, 1);
  16. if (d[3]) { date.setMonth(d[3] - 1); }
  17. if (d[5]) { date.setDate(d[5]); }
  18. if (d[7]) {
  19. date.setHours(parseInt(d[7], 10));
  20. }
  21. if (d[8]) { date.setMinutes(d[8]); }
  22. if (d[10]) { date.setSeconds(d[10]); }
  23. return date;
  24. }