Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Adding support for months and years #8

Closed
wants to merge 2 commits into from

3 participants

Miguel Angel Timo Tijhof Jörn Zaefferer
Miguel Angel

I also added a location file into Spanish example(I'm Mexican).

Miguel Angel Adding support for months and years
I also added a location file into Spanish example(I'm Mexican).
3f03972
Miguel Angel

By the way when revice localization files I realized that there are 2 files that change the format in the name:

localization/
├── jquery-prettydate-fr.js
└── jquery-prettydate-lv.js

It may be an idea to rename the same way as the others:

#Replacing the character '-' to '.'
git mv localization/jquery-prettydate-fr.js localization/jquery.prettydate-fr.js
git mv localization/jquery-prettydate-lv.js localization/jquery.prettydate-lv.js
jquery.prettydate.js
@@ -89,7 +91,9 @@ $.prettyDate.messages = {
89 91
 	hours: $.prettyDate.template("{0} hours ago"),
90 92
 	yesterday: "Yesterday",
91 93
 	days: $.prettyDate.template("{0} days ago"),
92  
-	weeks: $.prettyDate.template("{0} weeks ago")
  94
+	weeks: $.prettyDate.template("{0} weeks ago"),
  95
+	months: $.prettyDate.template("{0} mounths ago"),
1

months*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Timo Tijhof Krinkle referenced this pull request from a commit September 14, 2012
Commit has since been removed from the repository and is no longer available.
Miguel Angel Checking my error.
 Reviewing the singular and plural of weeks and months.
c2f606d
Miguel Angel

Hi,

I just made the appropriate changes:wink:.

Jörn Zaefferer jzaefferer closed this pull request from a commit September 14, 2012
Timo Tijhof 2012 Rewrite: v1.1.0pre
New:
* New parser, made as public API ($.prettyDate.parse).
* Timezones fully supported as supported by ES5 Date.parse and
  ISO 8601.
* Recognition of (+ unit tests)
 - 1 week
 - 1 month
 - # months
 - 1 year
 - # years
   I've taken months and years with a low-end margin (since days
   in a month/year varies). Also use a 2-week buffer between
   the date and the 1+ next year. So if something is 1 year and 2
   weeks ago, it shows 1 year not 2 years already.
* Documentation blocks.
* /demo: Add all variations (same as /test).
* /demo: Add dynamic language switcher menu

Changes:
* "isUTC" option no longer needed. ISO 8601 timestamps can
  contain timestamps themselves (and should!). Previously this
  was relevant because the lazy parsing implementation removed
  [TZ] from the string. But now that this is taken into
  consideration, it will be more accurate.
  I considered keeping it, but couldn't make it work reliably.
  It has to be in the timestamp itself for it to be relevant.
* Removed .fromUTC().
* Converted line endings to Unix (git-diff ^M warnings).
* Rename /localization and files to match jquery-ui convention.
  New directory: /i18n
  The filenames were mostly already there, renamed:
 - 'jquery-prettydate-fr.js'
 - 'jquery-prettydate-lv.js'
* Added new lines at EOFs.
* Update upstream libs.
* Update demo markup.
* Update unit tests.
* Update Dutch translation (i18n.nl).
* Bump version number to next +'pre'.

Issues:
* Fix indentation and missing semicolons in various places
* Fix "same has been deprecated since 2009 (e88049a0), use
   assert.deepEqual instead".
* Passed JSHint.
* Closes #2: Bad results when server and client timezones differ.
* Closes #6: "1 weeks" -> "1 week".
* Closes #8: Adding support for months and years.

Libs:
* curl 'http://code.jquery.com/jquery.js'; > libs/jquery.js
* git submodule add git://github.com/jquery/qunit.git libs/jquery.qunit
f4d3d0d
Jörn Zaefferer jzaefferer closed this in f4d3d0d September 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jul 15, 2012
Miguel Angel Adding support for months and years
I also added a location file into Spanish example(I'm Mexican).
3f03972
Sep 17, 2012
Miguel Angel Checking my error.
 Reviewing the singular and plural of weeks and months.
c2f606d
This page is out of date. Refresh to see the latest.
16  jquery.prettydate.js
@@ -64,7 +64,7 @@ $.prettyDate = {
64 64
 			diff = ($.prettyDate.now().getTime() - date.getTime()) / 1000,
65 65
 			day_diff = Math.floor(diff / 86400);
66 66
 
67  
-		if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
  67
+		if ( isNaN(day_diff) || day_diff < 0 )
68 68
 			return;
69 69
 
70 70
 		var messages = $.prettyDate.messages;
@@ -76,7 +76,11 @@ $.prettyDate = {
76 76
 				diff < 86400 && messages.hours(Math.floor( diff / 3600 ))) ||
77 77
 			day_diff == 1 && messages.yesterday ||
78 78
 			day_diff < 7 && messages.days(day_diff) ||
79  
-			day_diff < 31 && messages.weeks(Math.ceil( day_diff / 7 ));
  79
+			day_diff < 8 && messages.week ||
  80
+			day_diff < 31 && (Math.ceil(day_diff / 7 )!==4) && messages.weeks(Math.ceil(day_diff / 7 ))  ||
  81
+			(Math.ceil( day_diff / 31 )<2) && messages.month ||
  82
+			day_diff < 365 && messages.months(Math.ceil( day_diff / 31 )) ||
  83
+			day_diff > 365 && messages.years(Math.ceil( day_diff / 365 ));
80 84
 	}
81 85
 
82 86
 };
@@ -89,7 +93,11 @@ $.prettyDate.messages = {
89 93
 	hours: $.prettyDate.template("{0} hours ago"),
90 94
 	yesterday: "Yesterday",
91 95
 	days: $.prettyDate.template("{0} days ago"),
92  
-	weeks: $.prettyDate.template("{0} weeks ago")
  96
+	week: "1 week ago",
  97
+	weeks: $.prettyDate.template("{0} weeks ago"),
  98
+	month: "1 month ago",
  99
+	months: $.prettyDate.template("{0} months ago"),
  100
+	years: $.prettyDate.template("{0} years ago")
93 101
 };
94 102
 
95 103
 $.fn.prettyDate = function(options) {
@@ -115,4 +123,4 @@ $.fn.prettyDate = function(options) {
115 123
 	return this;
116 124
 };
117 125
 
118  
-})(jQuery);
  126
+})(jQuery);
6  localization/jquery.prettydate-es.js
@@ -7,5 +7,9 @@ $.prettyDate.messages = {
7 7
     hours: $.prettyDate.template("hace {0} horas"),
8 8
     yesterday: "ayer",
9 9
     days: $.prettyDate.template("hace {0} días"),
10  
-    weeks: $.prettyDate.template("hace {0} semanas")
  10
+    week: 'hace 1 semana',
  11
+    weeks: $.prettyDate.template("hace {0} semanas"),
  12
+    month: 'hace 1 mes',
  13
+    months: $.prettyDate.template("hace {0} meses"),
  14
+    years: $.prettyDate.template("hace {0} años")
11 15
 };
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.