Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added toBrowserTimeZone and prettyDate methods and refactored class integration code #37

Closed
wants to merge 4 commits into from

2 participants

@arjunballa

added toBrowserTimeZone and prettyDate methods and refactored class integration code

README.rdoc
@@ -72,6 +72,19 @@ The default shortDateFormat and longDateFormat are defined in the variables
#1 Test: 18/12/2009
#2 18~12~2009
+== Pretty date formatting
+Takes an ISO time and returns a string representing how long ago the date represents
+
+jQuery.format.prettyDate("2008-01-28T20:24:17Z") // => "2 hours ago"
+jQuery.format.prettyDate("2008-01-27T22:24:17Z") // => "Yesterday"
+jQuery.format.prettyDate("2008-01-26T22:24:17Z") // => "2 days ago"
+jQuery.format.prettyDate("2008-01-14T22:24:17Z") // => "2 weeks ago"
+jQuery.format.prettyDate("2007-12-15T22:24:17Z") // => undefined
+
+== toBrowserTimeZone
+jQuery.format.toBrowserTimeZone takes two parameters (value, format) and converts into browsers timezone.
+All input formats valid for jQuery.format.date are valid for this method.
+
@phstc Owner
phstc added a note

Could you add an example here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@phstc
Owner

Hey @arjunballa, tks for the PR.

Could you update it? It can't be automatically merge.

This pull request cannot be automatically merged.

Is test suite Test.html still passing?

@phstc
Owner

ping?

@arjunballa

I closed this pull request because of formatting issue and added a new one

@arjunballa arjunballa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2013
  1. @arjunballa
Commits on Jun 15, 2013
  1. @arjunballa

    reformatted, added toBrowserTimeZone and prettyDate methods, refactor…

    arjunballa authored
    …ed class integration code and added test cases
  2. @arjunballa

    Merge branch 'master' of github.com:phstc/jquery-dateFormat

    arjunballa authored
    Conflicts:
    	Test.html
    	jquery.dateFormat-1.0.js
  3. @arjunballa

    Update README.rdoc

    arjunballa authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -0,0 +1 @@
+*.project
View
17 README.rdoc
@@ -73,6 +73,23 @@ The default shortDateFormat and longDateFormat are defined in the variables
#1 Test: 18/12/2009
#2 18~12~2009
+== Pretty date formatting
+Takes an ISO time and returns a string representing how long ago the date represents
+
+
+ jQuery.format.prettyDate("2008-01-28T20:24:17Z") // => "2 hours ago"
+ jQuery.format.prettyDate("2008-01-27T22:24:17Z") // => "Yesterday"
+ jQuery.format.prettyDate("2008-01-26T22:24:17Z") // => "2 days ago"
+ jQuery.format.prettyDate("2008-01-14T22:24:17Z") // => "2 weeks ago"
+ jQuery.format.prettyDate("2007-12-15T22:24:17Z") // => more than 31 days
+
+
+== toBrowserTimeZone
+jQuery.format.toBrowserTimeZone(value, format) converts into browsers timezone.
+
+ value - String representing date or date object
+ format - All input formats valid for jQuery.format.date are valid for this method. The defaut format is MM/dd/yyyy.
+
== Test
This plugin was developed using http://jsunittest.com
View
19 document-ready-integration.js
@@ -0,0 +1,19 @@
+jQuery.format.date.defaultShortDateFormat = "dd/MM/yyyy";
+jQuery.format.date.defaultLongDateFormat = "dd/MM/yyyy hh:mm:ss";
+
+jQuery(document).ready(function () {
+ jQuery(".shortDateFormat").each(function (idx, elem) {
+ if (jQuery(elem).is(":input")) {
+ jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), jQuery.format.date.defaultShortDateFormat));
+ } else {
+ jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), jQuery.format.date.defaultShortDateFormat));
+ }
+ });
+ jQuery(".longDateFormat").each(function (idx, elem) {
+ if (jQuery(elem).is(":input")) {
+ jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), jQuery.format.date.defaultLongDateFormat));
+ } else {
+ jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), jQuery.format.date.defaultLongDateFormat));
+ }
+ });
+});
View
63 jquery.dateFormat-1.0.js
@@ -257,7 +257,7 @@
}
retValue += parseInt(time.hour, 10);
pattern = "";
- break;
+ break;
case "hh":
/* time.hour is "00" as string == is used instead of === */
var hour = (time.hour == 0 ? 12 : time.hour < 13 ? time.hour : time.hour - 12);
@@ -329,27 +329,48 @@
console.log(e);
return value;
}
- }
+ },
+ /*
+ * JavaScript Pretty Date
+ * Copyright (c) 2011 John Resig (ejohn.org)
+ * Licensed under the MIT and GPL licenses.
+ *
+ * Takes an ISO time and returns a string representing how long ago the date
+ * represents
+ *
+ * ("2008-01-28T20:24:17Z") // => "2 hours ago"
+ * ("2008-01-27T22:24:17Z") // => "Yesterday"
+ * ("2008-01-26T22:24:17Z") // => "2 days ago"
+ * ("2008-01-14T22:24:17Z") // => "2 weeks ago"
+ * ("2007-12-15T22:24:17Z") // => more than 31 days
+ *
+ */
+ prettyDate : function (time) {
+ var date;
+ var diff;
+ var day_diff;
+
+ if(typeof time === "string"){
+ date = new Date(time);
+ }
+ if(typeof time === "object"){
+ date = new Date(time.toString());
+ }
+ diff = (((new Date ()).getTime() - date.getTime()) / 1000);
+ day_diff = Math.floor(diff / 86400);
+
+ if (isNaN(day_diff) || day_diff < 0)
+ return;
+
+ if (day_diff >= 31)
+ return "more than 31 days";
+
+ return day_diff == 0 && (diff < 60 && "just now" || diff < 120 && "1 minute ago" || diff < 3600 && Math.floor(diff / 60) + " minutes ago" || diff < 7200 && "1 hour ago" || diff < 86400 && Math.floor(diff / 3600) + " hours ago") || day_diff == 1 && "Yesterday" || day_diff < 7 && day_diff + " days ago" || day_diff < 31 && Math.ceil(day_diff / 7) + " weeks ago";
+ },
+ toBrowserTimeZone : function (value, format) {
+ return this.date(value, format || "MM/dd/yyyy");
+ }
};
}());
}(jQuery));
-jQuery.format.date.defaultShortDateFormat = "dd/MM/yyyy";
-jQuery.format.date.defaultLongDateFormat = "dd/MM/yyyy HH:mm:ss";
-
-jQuery(document).ready(function () {
- jQuery(".shortDateFormat").each(function (idx, elem) {
- if (jQuery(elem).is(":input")) {
- jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), jQuery.format.date.defaultShortDateFormat));
- } else {
- jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), jQuery.format.date.defaultShortDateFormat));
- }
- });
- jQuery(".longDateFormat").each(function (idx, elem) {
- if (jQuery(elem).is(":input")) {
- jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), jQuery.format.date.defaultLongDateFormat));
- } else {
- jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), jQuery.format.date.defaultLongDateFormat));
- }
- });
-});
Something went wrong with that request. Please try again.