1 | dojo.provide("dojox.date.tests.relative"); |
---|
2 | dojo.require("dojox.date.relative"); |
---|
3 | dojo.require("dojo.date"); |
---|
4 | |
---|
5 | dojo.requireLocalization("dojo.cldr", "gregorian"); |
---|
6 | |
---|
7 | tests.register("dojox.date.tests.relative", |
---|
8 | [ |
---|
9 | { |
---|
10 | // Test formatting and parsing of dates in various locales pre-built in dojo.cldr |
---|
11 | // NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly |
---|
12 | // load resources here for specific locales: |
---|
13 | |
---|
14 | name: "date.locale", |
---|
15 | setUp: function(){ |
---|
16 | var partLocaleList = ["en-us", "zh-cn"]; |
---|
17 | |
---|
18 | dojo.forEach(partLocaleList, function(locale){ |
---|
19 | dojo.requireLocalization("dojo.cldr", "gregorian", locale); |
---|
20 | }); |
---|
21 | }, |
---|
22 | runTest: function(t){ |
---|
23 | }, |
---|
24 | tearDown: function(){ |
---|
25 | } |
---|
26 | }, |
---|
27 | { |
---|
28 | name: "format_dates", |
---|
29 | runTest: function(t){ |
---|
30 | //relative to "today", default locale |
---|
31 | var d = new Date(); |
---|
32 | t.is(dojo.date.locale.format(d, {selector: "time"}), dojox.date.relative.format(d)); |
---|
33 | |
---|
34 | //en-us: test the various relativities |
---|
35 | var opts = {locale: "en-us", relativeDate: new Date(2009, 1, 1, 5, 27, 34)}; |
---|
36 | t.is("3:32 AM", dojox.date.relative.format(new Date(2009, 1, 1, 3, 32, 26), opts)); |
---|
37 | t.is("Sat 8:32 PM", dojox.date.relative.format(new Date(2009, 0, 31, 20, 32, 26), opts)); |
---|
38 | t.is("Jan 1", dojox.date.relative.format(new Date(2009, 0, 1, 20, 32, 26), opts)); |
---|
39 | t.is("Jan 1, 2008", dojox.date.relative.format(new Date(2008, 0, 1, 0), opts)); |
---|
40 | |
---|
41 | //en-us: test various options as well as future dates and edge cases |
---|
42 | t.is("8:32 PM", dojox.date.relative.format(new Date(2009, 1, 1, 20, 32, 26), opts)); |
---|
43 | t.is("12:00 AM", dojox.date.relative.format(new Date(2009, 1, 1, 0), opts)); |
---|
44 | t.is("Jan 31", dojox.date.relative.format(new Date(2009, 0, 31, 20, 32, 26), dojo.delegate(opts, {weekCheck: false}))); |
---|
45 | t.is("Jan 1", dojox.date.relative.format(new Date(2009, 0, 1, 20, 32, 26), opts)); |
---|
46 | t.is("Feb 2", dojox.date.relative.format(new Date(2009, 1, 2, 20, 32, 26), opts)); |
---|
47 | t.is("Jan 1, 2010", dojox.date.relative.format(new Date(2010, 0, 1, 0), opts)); |
---|
48 | |
---|
49 | //zh-tw: test the various relativities |
---|
50 | opts.locale = "zh-cn"; |
---|
51 | t.is("\u4e0a\u53483:32", dojox.date.relative.format(new Date(2009, 1, 1, 3, 32, 26), opts)); |
---|
52 | t.is("\u5468\u516d \u4e0b\u53488:32", dojox.date.relative.format(new Date(2009, 0, 31, 20, 32, 26), opts)); |
---|
53 | t.is("1\u67081\u65e5", dojox.date.relative.format(new Date(2009, 0, 1, 20, 32, 26), opts)); |
---|
54 | t.is("2008-1-1", dojox.date.relative.format(new Date(2008, 0, 1, 0), opts)); |
---|
55 | } |
---|
56 | } |
---|
57 | ] |
---|
58 | ); |
---|