Skip to content

Commit

Permalink
2012 Rewrite: v1.1.0pre
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Krinkle committed Sep 14, 2012
1 parent 2fb5a28 commit f4d3d0d
Show file tree
Hide file tree
Showing 38 changed files with 9,965 additions and 6,596 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/jquery.qunit"]
path = libs/jquery.qunit
url = git://github.com/jquery/qunit.git
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs/
28 changes: 28 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"predef": [
"QUnit"
],

"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"plusplus": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": false,
"trailing": true,

"browser": true,
"jquery": true,

"nomen": true,
"onevar": true,
"white": true
}
231 changes: 157 additions & 74 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,87 +1,170 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>jQuery pretty date plugin demo</title>
<script src="../lib/jquery.js"></script>
<meta charset="utf-8">
<title>jQuery prettyDate Demo</title>
<script src="../libs/jquery.js"></script>
<script src="../jquery.prettydate.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #eee;
font: 14px/21px sans-serif;
color: #333;
position: relative;
}
h1 {
text-align: center;
padding: 1em 0;
}
a {
text-decoration: none;
color: #0645ad;
}
a:hover {
text-decoration: underline;
}
fieldset, p {
margin: 0.5em 0;
}
.fork {
position: fixed;
top: 0; right: 0;
background: url(https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67) no-repeat 100% 0;
width: 150px;
height: 150px;
float: right;
}
.entries {
margin: 0 auto 3em;
padding: 0.5em 0.5em 0;
background: #fff;
width: 500px;
overflow: hidden;
}
fieldset, .entry {
background: #f2f2f2;
border: 1px solid #ddd;
padding: 0.25em 0.5em;
margin-bottom: 0.5em;
list-style: none;
overflow: hidden;
}
.entry .extra {
float: right;
}
</style>
<script>
$(function() {
// set a fixed date for the demo to be independent of the current date
$.prettyDate.now = function() {
return new Date("2008/01/28 22:25:00");
jQuery(function ($) {
// Generate demo's with javascript to keep HTML less repetative
var zulus, $langs,
msgsEn = $.extend({}, $.prettyDate.messages),
$langMenu = $('<select>'),
$entries = $('.entries ul').empty();


function doPretty() {
$('.time').prettyDate({
// No need to update as the time is fixed
interval: false
});
}
$("a").prettyDate();
});
</script>
</head>
<body>

</body>
</html>
<ul>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-28T20:24:17Z"><span>January 28th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-27T22:24:17Z"><span>January 27th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
zulus = [
'2012-01-01T00:00:00Z',
'2008-01-28T22:24:30Z',
'2008-01-28T22:23:05Z',
'2008-01-28T22:20:05Z',
'2008-01-28T20:24:17Z',
'2008-01-27T08:00:00Z',
'2008-01-26T08:00:00Z',
'2008-01-21T08:00:00Z',
'2008-01-14T08:00:00Z',
'2007-12-28T08:00:00Z',
'2007-12-15T08:00:00Z',
'2007-01-14T08:00:00Z',
'2006-03-07T08:00:00Z'
];
$.each(zulus, function (i, zulu) {
$entries.append(
$('<li>', {
addClass: 'entry',
html: '<a href="#' + zulu + '">Blah blah blah</a>' +
' <small class="extra"><span class="time" title="' +
zulu + '">' + new Date($.prettyDate.parse(zulu)).toDateString() + '</span>' +
' &nbsp;&bull;&nbsp; ' + '<a class="author" href="#/author/john/">John Resig</a></small>'
})
);

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-26T22:24:17Z"><span>January 26th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
});

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-25T22:24:17Z"><span>January 25th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-24T22:24:17Z"><span>January 24th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
$langs = $.map([
'cn',
'da',
'de',
'es',
'fr',
'id',
'lv',
'nl',
'pl',
'pt-BR',
'sv',
'th',
'tr'
], function (lang) {
return $('<option>').text(lang).prop('value', lang);
});
$langs.unshift(
$('<option>').text('en').prop({
value: '',
selected: true
})
);

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-14T22:24:17Z"><span>January 14th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
$langMenu
.prop('id', 'lang-menu')
.append($langs)
.on('change', function () {
if (this.value !== '') {
// $.getScript, but with cache
$.ajax({
url: '../i18n/jquery.prettydate-' + this.value + '.js',
dateType: 'script',
cache: true
}).done(doPretty);
} else {
$.prettyDate.messages = msgsEn;
doPretty();
}
})
.wrap('<fieldset>')
.parent()
.prependTo('.entries');

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2008-01-04T22:24:17Z"><span>January 4th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
// Fixed date for the demo to be independent of the current date
// (prevents everything from becoming "5 years ago...")
$.prettyDate.now = function () {
return new Date(1201559100000);
}

</small>
</li>
<li class="entry" id="post57">
<p>blah blah blah...</p>
<small class="extra">
Posted <span class="time"><a href="/2008/01/blah/57/" title="2007-12-15T22:24:17Z"><span>December 15th, 2008</span></a></span>
by <span class="author"><a href="/john/">John Resig</a></span>
$('<p>').text('Local time: ' + $.prettyDate.now()).prependTo('.entries');

</small>
</li>
</ul>
doPretty();
});
</script>
</head>
<body>
<a class="fork" href="https://github.com/jzaefferer/jquery-prettydate" title="Fork jquery.prettydate on GitHub!"></a>
<h1><a href="./">jQuery prettyDate Demo</a></h1>
<div class="entries">
<ul><em>Loading...</em></ul>
<hr>
<p><a href="https://github.com/jzaefferer/jquery-prettydate">Source code: github.com/jzaefferer/jquery-prettydate</a></p>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-cn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Chinse */
$.extend($.prettyDate.messages, {
now: '刚刚',
minute: '1分钟前',
minutes: $.prettyDate.template('{0}分钟前'),
hour: '1小时前',
hours: $.prettyDate.template('{0}小时前'),
yesterday: '昨天',
days: $.prettyDate.template('{0}天前'),
weeks: $.prettyDate.template('{0}星期前')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-da.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Danish */
$.extend($.prettyDate.messages, {
now: 'lige nu',
minute: 'et minut siden',
minutes: $.prettyDate.template('{0} minutter siden'),
hour: 'en time siden',
hours: $.prettyDate.template('{0} timer siden'),
yesterday: 'i går',
days: $.prettyDate.template('{0} dage siden'),
weeks: $.prettyDate.template('{0} uger siden')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* German */
$.extend($.prettyDate.messages, {
now: 'gerade eben',
minute: 'vor einer Minute',
minutes: $.prettyDate.template('vor {0} Minuten'),
hour: 'vor einer Stunde',
hours: $.prettyDate.template('vor {0} Stunden'),
yesterday: 'gestern',
days: $.prettyDate.template('vor {0} Tagen'),
weeks: $.prettyDate.template('vor {0} Wochen')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Spanish */
$.extend($.prettyDate.messages, {
now: 'recién',
minute: 'hace 1 minuto',
minutes: $.prettyDate.template('hace {0} minutos'),
hour: 'hace 1 hora',
hours: $.prettyDate.template('hace {0} horas'),
yesterday: 'ayer',
days: $.prettyDate.template('hace {0} días'),
weeks: $.prettyDate.template('hace {0} semanas')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-fr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* French */
$.extend($.prettyDate.messages, {
now: 'à l\'instant',
minute: 'il y a 1 minute',
minutes: $.prettyDate.template(' il y a {0} minutes'),
hour: ' il y a 1 heure',
hours: $.prettyDate.template('il y a {0} heures'),
yesterday: 'Hier',
days: $.prettyDate.template('il y a {0} jours'),
weeks: $.prettyDate.template('il y a {0} semaines')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Indonesian */
$.extend($.prettyDate.messages, {
now: 'sekarang',
minute: '1 menit lalu',
minutes: $.prettyDate.template('{0} Menit lalu'),
hour: '1 jam lalu',
hours: $.prettyDate.template('{0} Jam lalu'),
yesterday: 'Kemarin',
days: $.prettyDate.template('{0} Hari lalu'),
weeks: $.prettyDate.template('{0} Minggu lalu')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-lv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Latvian */
$.extend($.prettyDate.messages, {
now: 'tikko',
minute: 'pirms minūtes',
minutes: $.prettyDate.template('pirms {0} minūtēm'),
hour: 'pirms stundas',
hours: $.prettyDate.template('pirms {0} stundām'),
yesterday: 'vakar',
days: $.prettyDate.template('pirms {0} dienām'),
weeks: $.prettyDate.template('pirms {0} nedēļām')
});
16 changes: 16 additions & 0 deletions i18n/jquery.prettydate-nl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Dutch */
$.extend($.prettyDate.messages, {
now: 'nu net',
minute: 'een minuut geleden',
minutes: $.prettyDate.template('{0} minuten geleden'),
hour: '1 uur geleden',
hours: $.prettyDate.template('{0} uur geleden'),
yesterday: 'gisteren',
days: $.prettyDate.template('{0} dagen geleden'),
week: '1 week geleden',
weeks: $.prettyDate.template('{0} weken geleden'),
month: '1 maand geleden',
months: $.prettyDate.template('{0} maanden geleden'),
year: '1 jaar geleden',
years: $.prettyDate.template('{0} jaren geleden')
});
11 changes: 11 additions & 0 deletions i18n/jquery.prettydate-pl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Polish */
$.extend($.prettyDate.messages, {
now: 'przed chwilą',
minute: 'minutę temu',
minutes: $.prettyDate.template('{0} minut temu'),
hour: 'godzinę temu',
hours: $.prettyDate.template('{0} godzin temu'),
yesterday: 'wczoraj',
days: $.prettyDate.template('{0} dni temu'),
weeks: $.prettyDate.template('{0} tygodni temu')
});
Loading

0 comments on commit f4d3d0d

Please sign in to comment.