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.

32 lines
1.4 KiB

  1. Date.padded2 = function(hour) { padded2 = hour.toString(); if ((parseInt(hour) < 10) || (parseInt(hour) == null)) padded2="0" + padded2; return padded2; }
  2. Date.prototype.getAMPMHour = function() { hour=Date.padded2(this.getHours()); return (hour == null) ? 00 : (hour > 24 ? hour - 24 : hour ) }
  3. Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "" : ""; }
  4. Date.prototype.toFormattedString = function(include_time){
  5. str = this.getDate() + "." + (this.getMonth() + 1) + "." + this.getFullYear();
  6. if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() }
  7. return str;
  8. }
  9. Date.parseFormattedString = function (string) {
  10. var regexp = '([0-9]{1,2})\.(([0-9]{1,2})\.(([0-9]{2,4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
  11. var d = string.match(new RegExp(regexp, "i"));
  12. if (d==null) return Date.parse(string); // at least give javascript a crack at it.
  13. var offset = 0;
  14. if (d[5] && d[5].length == 2) {
  15. // we got only two digits for the year...
  16. d[5] = Number(d[5]);
  17. if (d[5] > 30)
  18. d[5] += 1900;
  19. else
  20. d[5] += 2000;
  21. }
  22. var date = new Date(d[5], 0, 1);
  23. if (d[3]) { date.setMonth(d[3] - 1); }
  24. if (d[5]) { date.setDate(d[1]); }
  25. if (d[7]) {
  26. date.setHours(parseInt(d[7], 10));
  27. }
  28. if (d[8]) { date.setMinutes(d[8]); }
  29. if (d[10]) { date.setSeconds(d[10]); }
  30. return date;
  31. }