mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-04-03 08:09:42 -04:00
Compare commits
44 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b5a364d3a2 | ||
|
05a85b77f9 | ||
|
0d2a2145b2 | ||
|
0399e804db | ||
|
98d000543c | ||
|
c8b5b9365c | ||
|
14ff438930 | ||
|
2409c9f88d | ||
|
74736c8d07 | ||
|
4af2cf7135 | ||
|
f7c9c359cd | ||
|
bf9d361e4e | ||
|
66d0ef5277 | ||
|
dd17e5598f | ||
|
6822da82d9 | ||
|
cb1b0fe977 | ||
|
9b32f8cba6 | ||
|
2245c795d0 | ||
|
ec51ad8132 | ||
|
570327cf15 | ||
|
3a73f0fab1 | ||
|
5d7684fbf8 | ||
|
dc570fed47 | ||
|
9fac817b07 | ||
|
b374bd6dfb | ||
|
81f072ebb2 | ||
|
dceed3b1d9 | ||
|
fc90536dac | ||
|
61baa07698 | ||
|
4138f62c2b | ||
|
c72634b73d | ||
|
cca5898e18 | ||
|
2780816e44 | ||
|
300555d699 | ||
|
ed44a62689 | ||
|
500b808f7b | ||
|
c4a132d6b2 | ||
|
d0e161a164 | ||
|
9d6c2c6b64 | ||
|
873f0f7c10 | ||
|
8946a5eb49 | ||
|
f6c1dd4d0f | ||
|
61e23e15a7 | ||
|
9128386996 |
18 changed files with 326 additions and 71 deletions
CONTRIBUTING.mdREADME.markdownbower.jsonindex.htmljquery.timeago.js
locales
jquery.timeago.cs.jsjquery.timeago.cz.jsjquery.timeago.es-short.jsjquery.timeago.he.jsjquery.timeago.ro.jsjquery.timeago.rs.jsjquery.timeago.tr.jsjquery.timeago.vi.jsjquery.timeago.zh-CN.jsjquery.timeago.zh-TW.js
test
timeago.jquery.json
37
CONTRIBUTING.md
Normal file
37
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
## Want to Contribute?
|
||||
|
||||
Found an issue? Thank you for helping out by reporting it. Please describe the
|
||||
problem, what you tried, what you expected to see, and what you actually
|
||||
experienced. Please [re-read the documentation](http://timeago.yarp.com/) to
|
||||
make sure you're using the API as designed, but if you found something that's
|
||||
broken, we really appreciate your efforts in letting us know. Bonus points for
|
||||
submitting a failing test case to help us diagnose and potentially fix the
|
||||
issue.
|
||||
|
||||
## Want to Contribute?
|
||||
|
||||
Awesome. We love help, but before getting started, please read:
|
||||
|
||||
**[Don't "Push" Your Pull Requests](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)**
|
||||
|
||||
## Ready for a Pull-Request?
|
||||
|
||||
1. Fork the repo.
|
||||
|
||||
2. Run the tests. Run `rake` or open `open test/index.html`. We only take pull
|
||||
requests with passing tests, and it's great to know that you started from a
|
||||
clean slate.
|
||||
|
||||
3. Add a test for your change. Only refactoring and documentation change
|
||||
require no new tests. If you are adding functionality or fixing a bug, we
|
||||
need a test!
|
||||
|
||||
4. Make the test pass.
|
||||
|
||||
5. Push to your fork (hopefully this comes from a topical branch) and submit a
|
||||
pull request.
|
||||
|
||||
At this point you're waiting on us. Please keep in mind that OSS maintainers
|
||||
are often very busy. We'll do our best to at least comment on issues and
|
||||
pull-requests as soon as possible, but sometimes life gets in the way. We may
|
||||
also suggest some changes or improvements or alternatives.
|
|
@ -4,10 +4,26 @@ Timeago is a jQuery plugin that makes it easy to support automatically updating
|
|||
fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601
|
||||
formatted dates and times embedded in your HTML (à la microformats).
|
||||
|
||||
**If you like this project, please help by donating.**
|
||||
## How You Can Help
|
||||
|
||||
* Gittip: https://www.gittip.com/rmm5t/
|
||||
* Bitcoin: `1wzBnMjWVZfpiFMc5i2nzKT7sCBaZNfLK`
|
||||
**If you like this project, please help. [Donate via Gittip][gittip] or [buy me a coffee with Bitcoin][bitcoin].**<br>
|
||||
[][gittip]
|
||||
[][bitcoin]
|
||||
|
||||
**[Bitcoin][bitcoin]**: `1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m`<br>
|
||||
[![Bitcoin Donation][bitcoin-qr-small]][bitcoin-qr-big]
|
||||
|
||||
## Need Help?
|
||||
|
||||
**You can [book a session with me on Codementor][codementor].**<br>
|
||||
[][codementor]
|
||||
|
||||
[gittip]: https://www.gittip.com/rmm5t/ "Donate to rmm5t for open source!"
|
||||
[bitcoin]: https://blockchain.info/address/1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m "Buy rmm5t a coffee for open source!"
|
||||
[bitcoin-scheme]: bitcoin:1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m?amount=0.01&label=Coffee%20to%20rmm5t%20for%20Open%20Source "Buy rmm5t a coffee for open source!"
|
||||
[bitcoin-qr-small]: http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
|
||||
[bitcoin-qr-big]: http://chart.apis.google.com/chart?cht=qr&chs=500x500&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
|
||||
[codementor]: https://www.codementor.io/rmm5t?utm_campaign=profile&utm_source=button-rmm5t&utm_medium=shields "Book a session with rmm5t on Codementor!"
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -57,20 +73,22 @@ As time passes, the timestamps will automatically update.
|
|||
|
||||
## Changes
|
||||
|
||||
| Version | Notes |
|
||||
|---------|------------------------------------------------------------------|
|
||||
| 1.3.x | ([compare][compare-1.3]) Added updateFromDOM function; bug fixes |
|
||||
| 1.2.x | ([compare][compare-1.2]) Added cutoff setting |
|
||||
| 1.1.x | ([compare][compare-1.1]) Added update function |
|
||||
| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper |
|
||||
| 0.11.x | ([compare][compare-0.11]) natural rounding; locale updates; |
|
||||
| 0.10.x | ([compare][compare-0.10]) locale updates |
|
||||
| 0.9.x | ([compare][compare-0.9]) microsecond support; bug fixes |
|
||||
| 0.8.x | ([compare][compare-0.8]) `<time>` element support; bug fixes |
|
||||
| 0.7.x | ([compare][compare-0.7]) locale function overrides; unit tests |
|
||||
| ... | ... |
|
||||
| Version | Notes |
|
||||
|---------|---------------------------------------------------------------------------------|
|
||||
| 1.4.x | ([compare][compare-1.4]) Added allowPast setting |
|
||||
| 1.3.x | ([compare][compare-1.3]) Added updateFromDOM function; bug fixes; bower support |
|
||||
| 1.2.x | ([compare][compare-1.2]) Added cutoff setting |
|
||||
| 1.1.x | ([compare][compare-1.1]) Added update function |
|
||||
| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper |
|
||||
| 0.11.x | ([compare][compare-0.11]) natural rounding; locale updates; |
|
||||
| 0.10.x | ([compare][compare-0.10]) locale updates |
|
||||
| 0.9.x | ([compare][compare-0.9]) microsecond support; bug fixes |
|
||||
| 0.8.x | ([compare][compare-0.8]) `<time>` element support; bug fixes |
|
||||
| 0.7.x | ([compare][compare-0.7]) locale function overrides; unit tests |
|
||||
| ... | ... |
|
||||
|
||||
[compare-1.3]: https://github.com/rmm5t/jquery-timeago/compare/v1.2.0...v1.3.1
|
||||
[compare-1.4]: https://github.com/rmm5t/jquery-timeago/compare/v1.3.2...v1.4.1
|
||||
[compare-1.3]: https://github.com/rmm5t/jquery-timeago/compare/v1.2.0...v1.3.2
|
||||
[compare-1.2]: https://github.com/rmm5t/jquery-timeago/compare/v1.1.0...v1.2.0
|
||||
[compare-1.1]: https://github.com/rmm5t/jquery-timeago/compare/v1.0.2...v1.1.0
|
||||
[compare-1.0]: https://github.com/rmm5t/jquery-timeago/compare/v0.11.4...v1.0.2
|
||||
|
|
13
bower.json
Normal file
13
bower.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "jquery-timeago",
|
||||
"version": "1.4.1",
|
||||
"license": "MIT",
|
||||
"main": "jquery.timeago.js",
|
||||
"ignore": [
|
||||
"test",
|
||||
"vendor"
|
||||
],
|
||||
"dependencies": {
|
||||
"jquery": ">=1.4"
|
||||
}
|
||||
}
|
|
@ -116,6 +116,15 @@ jQuery.timeago(jQuery("abbr#some_id")); //=> "<span id="prog_element"></spa
|
|||
<pre>
|
||||
jQuery.timeago.settings.allowFuture = true;</pre>
|
||||
|
||||
<p class="how">
|
||||
To disable timestamps in the past, use the <tt>allowPast</tt> setting.
|
||||
This setting is set to true by default. When set to false, if the time is in the past then instead of displaying a message like "5 minutes ago" a static message will be displayed.
|
||||
The staic message displayed can be configured with the <tt>strings.inPast</tt> setting:
|
||||
</p>
|
||||
<pre>
|
||||
jQuery.timeago.settings.strings.inPast = "time has elapsed";
|
||||
jQuery.timeago.settings.allowPast = false;</pre>
|
||||
|
||||
<h3>Excusez-moi?</h3>
|
||||
<p>
|
||||
Yes, timeago has locale/i18n/language support. Here are some <a href="https://github.com/rmm5t/jquery-timeago/tree/master/locales">configuration examples</a>. Please submit a <a href="https://github.com/rmm5t/jquery-timeago">GitHub pull request</a> for corrections or additional languages.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
||||
*
|
||||
* @name timeago
|
||||
* @version 1.3.1
|
||||
* @version 1.4.1
|
||||
* @requires jQuery v1.2.3+
|
||||
* @author Ryan McGeary
|
||||
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||
|
@ -39,6 +39,7 @@
|
|||
$.extend($.timeago, {
|
||||
settings: {
|
||||
refreshMillis: 60000,
|
||||
allowPast: true,
|
||||
allowFuture: false,
|
||||
localeTitle: false,
|
||||
cutoff: 0,
|
||||
|
@ -47,6 +48,7 @@
|
|||
prefixFromNow: null,
|
||||
suffixAgo: "ago",
|
||||
suffixFromNow: "from now",
|
||||
inPast: 'any moment now',
|
||||
seconds: "less than a minute",
|
||||
minute: "about a minute",
|
||||
minutes: "%d minutes",
|
||||
|
@ -62,7 +64,12 @@
|
|||
numbers: []
|
||||
}
|
||||
},
|
||||
|
||||
inWords: function(distanceMillis) {
|
||||
if(!this.settings.allowPast && ! this.settings.allowFuture) {
|
||||
throw 'timeago allowPast and allowFuture settings can not both be set to false.';
|
||||
}
|
||||
|
||||
var $l = this.settings.strings;
|
||||
var prefix = $l.prefixAgo;
|
||||
var suffix = $l.suffixAgo;
|
||||
|
@ -73,6 +80,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
if(!this.settings.allowPast && distanceMillis >= 0) {
|
||||
return this.settings.strings.inPast;
|
||||
}
|
||||
|
||||
var seconds = Math.abs(distanceMillis) / 1000;
|
||||
var minutes = seconds / 60;
|
||||
var hours = minutes / 60;
|
||||
|
@ -101,6 +112,7 @@
|
|||
if ($l.wordSeparator === undefined) { separator = " "; }
|
||||
return $.trim([prefix, words, suffix].join(separator));
|
||||
},
|
||||
|
||||
parse: function(iso8601) {
|
||||
var s = $.trim(iso8601);
|
||||
s = s.replace(/\.\d+/,""); // remove milliseconds
|
||||
|
@ -163,11 +175,18 @@
|
|||
};
|
||||
|
||||
function refresh() {
|
||||
//check if it's still visible
|
||||
if(!$.contains(document.documentElement,this)){
|
||||
//stop if it has been removed
|
||||
$(this).timeago("dispose");
|
||||
return this;
|
||||
}
|
||||
|
||||
var data = prepareData(this);
|
||||
var $s = $t.settings;
|
||||
|
||||
if (!isNaN(data.datetime)) {
|
||||
if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) {
|
||||
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
||||
$(this).text(inWords(data.datetime));
|
||||
}
|
||||
}
|
||||
|
|
24
locales/jquery.timeago.cs.js
Normal file
24
locales/jquery.timeago.cs.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Czech
|
||||
(function() {
|
||||
function f(n, d, a) {
|
||||
return a[d>=0 ? 0 : a.length==2 || n<5 ? 1 : 2];
|
||||
}
|
||||
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: 'před',
|
||||
prefixFromNow: 'za',
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
seconds: function(n, d) {return f(n, d, ['méně než minutou', 'méně než minutu'])},
|
||||
minute: function(n, d) {return f(n, d, ['minutou', 'minutu'])},
|
||||
minutes: function(n, d) {return f(n, d, ['%d minutami', '%d minuty', '%d minut'])},
|
||||
hour: function(n, d) {return f(n, d, ['hodinou', 'hodinu'])},
|
||||
hours: function(n, d) {return f(n, d, ['%d hodinami', '%d hodiny', '%d hodin'])},
|
||||
day: function(n, d) {return f(n, d, ['%d dnem', '%d den'])},
|
||||
days: function(n, d) {return f(n, d, ['%d dny', '%d dny', '%d dní'])},
|
||||
month: function(n, d) {return f(n, d, ['%d měsícem', '%d měsíc'])},
|
||||
months: function(n, d) {return f(n, d, ['%d měsící', '%d měsíce', '%d měsíců'])},
|
||||
year: function(n, d) {return f(n, d, ['%d rokem', '%d rok'])},
|
||||
years: function(n, d) {return f(n, d, ['%d lety', '%d roky', '%d let'])}
|
||||
};
|
||||
})();
|
|
@ -1,18 +0,0 @@
|
|||
// Czech
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "před",
|
||||
prefixFromNow: null,
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
seconds: "méně než minutou",
|
||||
minute: "minutou",
|
||||
minutes: "%d minutami",
|
||||
hour: "hodinou",
|
||||
hours: "%d hodinami",
|
||||
day: "1 dnem",
|
||||
days: "%d dny",
|
||||
month: "1 měsícem",
|
||||
months: "%d měsíci",
|
||||
year: "1 rokem",
|
||||
years: "%d roky"
|
||||
};
|
20
locales/jquery.timeago.es-short.js
Normal file
20
locales/jquery.timeago.es-short.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Spanish shortened
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "",
|
||||
suffixFromNow: "",
|
||||
seconds: "1m",
|
||||
minute: "1m",
|
||||
minutes: "%dm",
|
||||
hour: "1h",
|
||||
hours: "%dh",
|
||||
day: "1d",
|
||||
days: "%dd",
|
||||
month: "1me",
|
||||
months: "%dme",
|
||||
year: "1a",
|
||||
years: "%da",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
// Hebrew
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "לפני",
|
||||
prefixFromNow: "מעכשיו",
|
||||
prefixFromNow: "עוד",
|
||||
suffixAgo: "",
|
||||
suffixFromNow: "",
|
||||
seconds: "פחות מדקה",
|
||||
|
@ -15,4 +15,4 @@ jQuery.timeago.settings.strings = {
|
|||
months: "%d חודשים",
|
||||
year: "שנה",
|
||||
years: "%d שנים"
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Romanian
|
||||
$.timeago.settings.strings = {
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "acum",
|
||||
prefixFromNow: "in timp de",
|
||||
suffixAgo: "",
|
||||
|
@ -15,4 +15,4 @@ $.timeago.settings.strings = {
|
|||
months: "%d luni",
|
||||
year: "un an",
|
||||
years: "%d ani"
|
||||
};
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
months: function (value) {
|
||||
return numpf(value, "%d mesec", "%d meseca", "%d meseci");
|
||||
},
|
||||
year: "pre godinu dana",
|
||||
year: "godinu dana",
|
||||
years: function (value) {
|
||||
return numpf(value, "%d godinu", "%d godine", "%d godina");
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Turkish
|
||||
jQuery.extend($.timeago.settings.strings, {
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: 'önce',
|
||||
suffixFromNow: null,
|
||||
seconds: '1 dakikadan',
|
||||
|
@ -13,4 +13,4 @@ jQuery.extend($.timeago.settings.strings, {
|
|||
months: '%d ay',
|
||||
year: '1 yıl',
|
||||
years: '%d yıl'
|
||||
});
|
||||
};
|
||||
|
|
20
locales/jquery.timeago.vi.js
Normal file
20
locales/jquery.timeago.vi.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Vietnamese
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: 'cách đây',
|
||||
prefixFromNow: null,
|
||||
suffixAgo: null,
|
||||
suffixFromNow: "trước",
|
||||
seconds: "chưa đến một phút",
|
||||
minute: "khoảng một phút",
|
||||
minutes: "%d phút",
|
||||
hour: "khoảng một tiếng",
|
||||
hours: "khoảng %d tiếng",
|
||||
day: "một ngày",
|
||||
days: "%d ngày",
|
||||
month: "khoảng một tháng",
|
||||
months: "%d tháng",
|
||||
year: "khoảng một năm",
|
||||
years: "%d năm",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
};
|
|
@ -4,17 +4,17 @@ jQuery.timeago.settings.strings = {
|
|||
prefixFromNow: "从现在开始",
|
||||
suffixAgo: "之前",
|
||||
suffixFromNow: null,
|
||||
seconds: "不到 1 分钟",
|
||||
minute: "大约 1 分钟",
|
||||
minutes: "%d 分钟",
|
||||
hour: "大约 1 小时",
|
||||
hours: "大约 %d 小时",
|
||||
day: "1 天",
|
||||
days: "%d 天",
|
||||
month: "大约 1 个月",
|
||||
months: "%d 月",
|
||||
year: "大约 1 年",
|
||||
years: "%d 年",
|
||||
seconds: "不到1分钟",
|
||||
minute: "大约1分钟",
|
||||
minutes: "%d分钟",
|
||||
hour: "大约1小时",
|
||||
hours: "大约%d小时",
|
||||
day: "1天",
|
||||
days: "%d天",
|
||||
month: "大约1个月",
|
||||
months: "%d月",
|
||||
year: "大约1年",
|
||||
years: "%d年",
|
||||
numbers: [],
|
||||
wordSeparator: ""
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,17 +4,17 @@ jQuery.timeago.settings.strings = {
|
|||
prefixFromNow: "從現在開始",
|
||||
suffixAgo: "之前",
|
||||
suffixFromNow: null,
|
||||
seconds: "不到 1 分鐘",
|
||||
minute: "大約 1 分鐘",
|
||||
minutes: "%d 分鐘",
|
||||
hour: "大約 1 小時",
|
||||
hours: "%d 小時",
|
||||
day: "大約 1 天",
|
||||
days: "%d 天",
|
||||
month: "大約 1 個月",
|
||||
months: "%d 個月",
|
||||
year: "大約 1 年",
|
||||
years: "%d 年",
|
||||
seconds: "不到1分鐘",
|
||||
minute: "大約1分鐘",
|
||||
minutes: "%d分鐘",
|
||||
hour: "大約1小時",
|
||||
hours: "%d小時",
|
||||
day: "大約1天",
|
||||
days: "%d天",
|
||||
month: "大約1個月",
|
||||
months: "%d個月",
|
||||
year: "大約1年",
|
||||
years: "%d年",
|
||||
numbers: [],
|
||||
wordSeparator: ""
|
||||
};
|
||||
|
|
|
@ -65,9 +65,13 @@
|
|||
|
||||
<h2>Cutoff</h2>
|
||||
|
||||
<p>Date that is older than cutoff: <abbr class="timeago cutoff doCutoff" title="1978-12-18">(this should be displayed)</abbr></p>
|
||||
<p>Date that is before a past cutoff: <abbr class="timeago cutoff doCutoffPast" title="1978-12-18">(this should be displayed)</abbr></p>
|
||||
|
||||
<p>Date that is newer than cutoff: <abbr class="timeago loaded cutoff dontCutoff">(you shouldn't see this)</abbr></p>
|
||||
<p>Date that is after a past cutoff: <abbr class="timeago loaded cutoff dontCutoffPast">(you shouldn't see this)</abbr></p>
|
||||
|
||||
<p>Date that is past a future cutoff: <abbr class="timeago cutoff doCutoffFuture" title="2999-12-18">(this should be displayed)</abbr></p>
|
||||
|
||||
<p>Date that is before a future cutoff: <abbr class="timeago loaded cutoff dontCutoffFuture">(you shouldn't see this)</abbr></p>
|
||||
|
||||
<h2>Errors</h2>
|
||||
|
||||
|
@ -190,6 +194,19 @@
|
|||
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
|
||||
</ul>
|
||||
|
||||
<h2>Do Not Allow Future</h2>
|
||||
|
||||
<ul>
|
||||
<li><abbr id="testAllowFutureFalse1" class="doNotAllowFuture" title="2012-01-01T09:24:17Z">(you shouldn't see this)</abbr></li>
|
||||
</ul>
|
||||
|
||||
<h2>Do Not Allow Past</h2>
|
||||
|
||||
<ul>
|
||||
<li><abbr id="testAllowPastFalse1" class="doNotAllowPast" title="2008-01-01T09:24:17Z">(you shouldn't see this)</abbr></li>
|
||||
<li><abbr id="testAllowPastAndFutureFalse" title="2008-01-01T09:24:17Z"></abbr></li>
|
||||
</ul>
|
||||
|
||||
<h2>Disposal</h2>
|
||||
<p><abbr class="disposal disposed"></abbr></p>
|
||||
<p><abbr class="disposal notDisposed"></abbr></p>
|
||||
|
@ -243,6 +260,14 @@
|
|||
$("abbr.tonumbers").each(toWords);
|
||||
unloadNumbers();
|
||||
|
||||
loadDoNotAllowFuture();
|
||||
$("abbr.doNotAllowFuture").timeago();
|
||||
unloadDoNotAllowFuture();
|
||||
|
||||
loadDoNotAllowPast();
|
||||
$("abbr.doNotAllowPast").timeago();
|
||||
unloadDoNotAllowPast();
|
||||
|
||||
setupDisposal();
|
||||
|
||||
loadYoungOldYears();
|
||||
|
@ -311,13 +336,25 @@
|
|||
module("Cutoff");
|
||||
|
||||
test("should not change dates older than cutoff setting", function () {
|
||||
ok(testElements("abbr.doCutoff", function (element) {
|
||||
ok(testElements("abbr.doCutoffPast", function (element) {
|
||||
return (element.html() === "(this should be displayed)");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should change dates newer than cutoff setting", function () {
|
||||
ok(testElements("abbr.dontCutoff", function (element) {
|
||||
ok(testElements("abbr.dontCutoffPast", function (element) {
|
||||
return (element.html() === "less than a minute ago");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should not change dates older than cutoff setting", function () {
|
||||
ok(testElements("abbr.doCutoffFuture", function (element) {
|
||||
return (element.html() === "(this should be displayed)");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should change dates newer than cutoff setting", function () {
|
||||
ok(testElements("abbr.dontCutoffFuture", function (element) {
|
||||
return (element.html() === "less than a minute ago");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
@ -595,6 +632,36 @@
|
|||
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
||||
});
|
||||
|
||||
module("Allow Future and Past");
|
||||
|
||||
// if allowFuture is false, then a minute into the future is actually reported as a minute in the past.
|
||||
// we did not want to alter the current behavior and break backwards compatability
|
||||
test("allow future false with a future date moves time backwards", function () {
|
||||
equal($("#testAllowFutureFalse1").html(), "2 years ago");
|
||||
});
|
||||
|
||||
test("allow future false with a future date moves time backwards", function () {
|
||||
equal($("#testAllowPastFalse1").html(), "in the past");
|
||||
});
|
||||
|
||||
test("throws if allowPast and allowFuture are both false", function () {
|
||||
// setup
|
||||
var origAllowFuture = $.timeago.settings.allowFuture;
|
||||
var origAllowPast = $.timeago.settings.allowPast;
|
||||
$.timeago.settings.allowFuture = false;
|
||||
$.timeago.settings.allowPast = false;
|
||||
|
||||
try {
|
||||
throws(function () {
|
||||
$("#testAllowPastAndFutureFalse").timeago();
|
||||
});
|
||||
} finally {
|
||||
// teardown
|
||||
$.timeago.settings.allowFuture = origAllowFuture;
|
||||
$.timeago.settings.allowPast = origAllowPast;
|
||||
}
|
||||
});
|
||||
|
||||
module("Disposal");
|
||||
|
||||
asyncTest("disposal", function() {
|
||||
|
|
|
@ -131,3 +131,49 @@ function loadYoungOldYears() {
|
|||
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
|
||||
});
|
||||
}
|
||||
|
||||
function loadDoNotAllowFuture() {
|
||||
var mockDateToUse = "2010-01-01";
|
||||
$.timeago.settings.allowFuture = false;
|
||||
enableMockedDate(mockDateToUse);
|
||||
}
|
||||
|
||||
function unloadDoNotAllowFuture() {
|
||||
$.timeago.settings.allowFuture = true;
|
||||
disableMockedDate();
|
||||
}
|
||||
|
||||
function loadDoNotAllowPast() {
|
||||
var mockDateToUse = "2010-01-01";
|
||||
$.timeago.settings.allowFuture = true;
|
||||
$.timeago.settings.allowPast = false;
|
||||
$.timeago.settings.strings.inPast = "in the past";
|
||||
enableMockedDate(mockDateToUse);
|
||||
}
|
||||
|
||||
function unloadDoNotAllowPast() {
|
||||
$.timeago.settings.allowFuture = true;
|
||||
$.timeago.settings.allowPast = true;
|
||||
disableMockedDate();
|
||||
}
|
||||
|
||||
function enableMockedDate(dateToReturn) {
|
||||
var mockDate = dateToReturn;
|
||||
window.NativeDate = Date;
|
||||
window.Date = function () {
|
||||
if(arguments.length === 0) {
|
||||
return new window.NativeDate(mockDate);
|
||||
} else if(arguments.length === 1) {
|
||||
return new window.NativeDate(arguments[0]);
|
||||
} else if(arguments.length === 7) {
|
||||
return new window.NativeDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
|
||||
} else {
|
||||
throw "Mocking Date with this number of parameters is not implemented.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function disableMockedDate() {
|
||||
window.Date = window.NativeDate;
|
||||
delete window.NativeDate;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "timeago",
|
||||
"version": "1.3.1",
|
||||
"version": "1.4.1",
|
||||
"title": "jQuery Timeago",
|
||||
"author": {
|
||||
"name": "Ryan McGeary",
|
||||
|
|
Loading…
Add table
Reference in a new issue