mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-30 19:06:42 +00:00
Add support for working with negative dates
See discussion https://groups.google.com/g/tiddlywiki/c/aHlyaHr93Io/m/vGcDa6lxAgAJ
This commit is contained in:
@@ -25,6 +25,16 @@ describe("Utility tests", function() {
|
||||
expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]);
|
||||
});
|
||||
|
||||
it("should handle parsing a date", function() {
|
||||
var pd = function(v) {
|
||||
return $tw.utils.parseDate(v).toString();
|
||||
};
|
||||
expect(pd("20150428204930183")).toEqual("Tue Apr 28 2015 21:49:30 GMT+0100 (British Summer Time)");
|
||||
expect(pd("-20150428204930183")).toEqual("Sun Apr 28 -2015 20:48:15 GMT-0001 (British Summer Time)");
|
||||
expect(pd("00730428204930183")).toEqual("Fri Apr 28 0073 20:48:15 GMT-0001 (British Summer Time)");
|
||||
expect(pd("-00730428204930183")).toEqual("Thu Apr 28 -0073 20:48:15 GMT-0001 (British Summer Time)");
|
||||
});
|
||||
|
||||
it("should handle base64 encoding emojis", function() {
|
||||
var booksEmoji = "📚";
|
||||
expect(booksEmoji).toBe(booksEmoji);
|
||||
@@ -62,6 +72,8 @@ describe("Utility tests", function() {
|
||||
var fds = $tw.utils.formatDateString,
|
||||
// nov is month: 10!
|
||||
d = new Date(2014,10,9,17,41,28,542);
|
||||
expect(fds(d,"{era:bce||ce}")).toBe("ce");
|
||||
expect(fds(d,"YYYY")).toBe("2014");
|
||||
expect(fds(d,"DDD DD MMM YYYY")).toBe("Sunday 9 November 2014");
|
||||
expect(fds(d,"ddd hh mm ssss")).toBe("Sun 17 41 2828");
|
||||
expect(fds(d,"MM0DD")).toBe("1109");
|
||||
@@ -92,6 +104,19 @@ describe("Utility tests", function() {
|
||||
d = new Date(2014,11,29,23,59,59);
|
||||
expect(fds(d,"WW")).toBe("1");
|
||||
expect(fds(d,"wYYYY")).toBe("2015");
|
||||
|
||||
// Negative years
|
||||
d = new Date(-2014,10,9,17,41,28,542);
|
||||
expect(fds(d,"YYYY")).toBe("-2014");
|
||||
expect(fds(d,"aYYYY")).toBe("2014");
|
||||
expect(fds(d,"{era:bce||ce}")).toBe("bce");
|
||||
|
||||
// Zero years
|
||||
d = new Date(0,10,9,17,41,28,542);
|
||||
d.setUTCFullYear(0); // See https://stackoverflow.com/a/5870822
|
||||
expect(fds(d,"YYYY")).toBe("0000");
|
||||
expect(fds(d,"aYYYY")).toBe("0000");
|
||||
expect(fds(d,"{era:bce|z|ce}")).toBe("z");
|
||||
});
|
||||
|
||||
it("should parse text references", function() {
|
||||
|
||||
Reference in New Issue
Block a user