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.

24 lines
862 B

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