Debian Codegraph @

docs/example-parsers-dates.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter - Assorted date parsers</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link rel="stylesheet" href="css/jq.css">
12 <link href="css/prettify.css" rel="stylesheet">
13 <script src="js/prettify.js"></script>
14 <script src="js/docs.js"></script>
15 <style>
16 th { width: 14%; }
17 </style>
18
19 <link href="../css/theme.blue.css" rel="stylesheet">
20 <script src="../js/jquery.tablesorter.js"></script>
21
22 <!-- load month, weekday and two digit year parsers -->
23 <script src="../js/parsers/parser-date-month.js"></script>
24 <script src="../js/parsers/parser-date-weekday.js"></script>
25 <script src="../js/parsers/parser-date-two-digit-year.js"></script>
26
27 <!-- https://sugarjs.com/docs/#/DateParsing -->
28 <script src="js/sugar.min.js"></script>
29 <script src="../js/parsers/parser-date.js"></script>
30
31 <script id="js">$(function() {
32
33 // See https://mottie.github.io/tablesorter/docs/example-widget-grouping.html
34 // for details on how to use CLDR data for a locale to add data for this parser
35 // CLDR returns { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... }
36
37 // or copy the data directly as it is shown here:
38 // ************************
39 // French localization modified from days "abbreviated" format
40 // https://github.com/unicode-cldr/cldr-dates-modern/blob/master/main/fr/ca-gregorian.json
41 // It does *not* include the periods
42 $.tablesorter.dates.weekdays.fr = {
43 "sun" : "Dim",
44 "mon" : "Lun",
45 "tue" : "Mar",
46 "wed" : "Mer",
47 "thu" : "Jeu",
48 "fri" : "Ven",
49 "sat" : "Sam"
50 };
51
52 // CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" }
53 // French localization modified from months "abbreviated" format
54 // https://github.com/unicode-cldr/cldr-dates-modern/blob/master/main/fr/ca-gregorian.json
55 // It does *not* include the periods
56 $.tablesorter.dates.months.fr = {
57 "1" : "Janv",
58 "2" : "Févr",
59 "3" : "Mars",
60 "4" : "Avr",
61 "5" : "Mai",
62 "6" : "Juin",
63 "7" : "Juil",
64 "8" : "Août",
65 "9" : "Sept",
66 "10" : "Oct",
67 "11" : "Nov",
68 "12" : "Déc"
69 };
70
71 // call the tablesorter plugin
72 $("table").tablesorter({
73 theme : 'blue',
74 // option used by weekday, month & globalize parsers (v2.24.1)
75 globalize : {
76 // columns that use French data
77 2 : { lang: 'fr' },
78 4 : { lang: 'fr' }
79 },
80 widgets : ["zebra"],
81 // date range used by the two-digit year parser (added v2.14.0)
82 dateRange : 30
83 });
84
85 });</script>
86 </head>
87 <body>
88 <div id="banner">
89 <h1>table<em>sorter</em></h1>
90 <h2>Assorted date parsers</h2>
91 <h3>Flexible client-side table sorting</h3>
92 <a href="index.html">Back to documentation</a>
93 </div>
94 <div id="main">
95
96 <p class="tip">
97 <em>NOTE!</em>
98 </p>
99 <ul>
100 <li>In <span class="version">v2.24.1</span>,
101 <ul>
102 <li>Updated weekday &amp; month parsers to better integrate with <a href="https://github.com/jquery/globalize">jQuery Globalize</a>.</li>
103 <li>This demo now includes a column for French named weekdays &amp; months.</li>
104 </ul>
105 </li>
106 <li>Parse Dates with these parsers
107 <ul>
108 <li>The "Date" column is using the <a href="https://sugarjs.com/docs/#/DateParsing">sugar</a> library to parse dates. Make sure to include the sugar library and the sugar-date-parser.</li>
109 <li>The "Weekday" column uses the included "weekday" parser. You can modify parser to match whatever language you are using.</li>
110 <li>The "Month" column uses the included "month" parser. You can also modify the month names within the parser to match whatever language you are using.</li>
111 <li>The "Year" column is just using the included two digit year parser:
112 <ul>
113 <li>Formats for "mmddyy", "ddmmyy" and "yymmdd" are available</li>
114 <li>Within the parser code is a <code>range</code> variable which is set to <code>50</code> years range, which sets the date be within +/- range of the listed two digit year.</li>
115 <li>So if the current year is <code>2020</code>, and the listed two digit year is <code>80</code> (<code>2080 - 2020 &gt; 50</code>), it becomes <code>1980</code>.</li>
116 <li>If the listed two digit year is <code>50</code> (<code>2050 - 2020 &lt; 50</code>), then it becomes <code>2050</code>. I hope that makes it clearer.</li>
117 <li>Try out the two digit year calculator below the table.</li>
118 <li>In <span class="version">v2.14.0</span>, the range can be set using the <code>dateRange</code> option (see the initialization code below).</li>
119 </ul>
120 </li>
121 <li>The "Time" column is using the built-in time parser which has been always been included with tablesorter .</li>
122 </ul>
123 </li>
124 </ul>
125
126 <h1>Demo</h1>
127 <div id="demo"><table class="tablesorter">
128 <thead>
129 <tr>
130 <th class="sorter-sugar">Date</th>
131 <th class="sorter-weekday">Weekday</th>
132 <th class="sorter-weekday">Weekday (French)</th>
133 <th class="sorter-month">Month</th>
134 <th class="sorter-month">Month (French)</th>
135 <th class="sorter-mmddyy">MM/DD/YY</th> <!-- "sorter-ddmmyy" also available -->
136 <th class="sorter-time">Time</th>
137 </tr>
138 </thead>
139 <tbody>
140 <tr><td>next friday</td><td>Friday</td><td>Vendredi</td><td>Aug</td><td>Août</td><td>02/1/16</td><td>12:00 PM</td></tr>
141 <tr><td>today</td><td>Sunday</td><td>Dim</td><td>September</td><td>Septembre</td><td>1/2/16</td><td>00:00</td></tr>
142 <tr><td>last Tuesday</td><td>Fri</td><td>Ven</td><td>Mar</td><td>Mars</td><td>11/1/15</td><td>18:00</td></tr>
143 <tr><td>the day after tomorrow</td><td>Wed</td><td>Mer</td><td>July</td><td>Juillet</td><td>01/1/16</td><td>13:00</td></tr>
144 <tr><td>2010-05-25T12:30:40.299+01:00</td><td>Monday</td><td>Lun</td><td>Jan</td><td>Janvier</td><td>1/11/15</td><td>1:30 PM</td></tr>
145 <tr><td>May 25th of next year</td><td>Tues</td><td>Mardi</td><td>Nov</td><td>Novembre</td><td>1/1/15</td><td>14:00</td></tr>
146 <tr><td>25 May 2010</td><td>Tuesday</td><td>Mar</td><td>November</td><td>Nov</td><td>3/1/15</td><td>1:58 PM</td></tr>
147 <tr><td>the last day of March</td><td>Sat</td><td>Sam</td><td>December</td><td>Décembre</td><td>1/15/15</td><td>2:10 PM</td></tr>
148 <tr><td>last month</td><td>Wednesday</td><td>Mercredi</td><td>April</td><td>Avr</td><td>11/11/16</td><td>13:50</td></tr>
149 <tr><td>one day before yesterday</td><td>Thursday</td><td>Jeudi</td><td>Feb</td><td>Février</td><td>5/1/15</td><td>4:00 AM</td></tr>
150 </tbody>
151 </table></div>
152
153 <h3>Two digit year calculator:</h3>
154 <div>two digit year <input class="tdy" type="number" min="0" max="99" value="20"> becomes <span class="result">2020</span></div>
155 <div class="params">
156 ( <label>range</label> <input class="range" type="number" value="50" min="0" max="99">
157 <label>"current year"</label> <input class="current" type="number" value="2011" min="1900" max="9999"> )
158 </div>
159
160 <h1>Page Header</h1>
161 <div>
162 <pre class="prettyprint lang-html">&lt;!-- blue theme stylesheet with additional css styles added in v2.0.17 --&gt;
163 &lt;link rel=&quot;stylesheet&quot; href=&quot;../css/theme.blue.css&quot;&gt;
164 &lt;!-- tablesorter plugin --&gt;
165 &lt;script src=&quot;../js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
166
167 &lt;!-- load month, weekday and two digit year parsers --&gt;
168 &lt;script src=&quot;../js/parsers/parser-date-month.js&quot;&gt;&lt;/script&gt;
169 &lt;script src=&quot;../js/parsers/parser-date-weekday.js&quot;&gt;&lt;/script&gt;
170 &lt;script src=&quot;../js/parsers/parser-date-two-digit-year.js&quot;&gt;&lt;/script&gt;
171
172 &lt;!-- https://sugarjs.com/docs/#/DateParsing --&gt;
173 &lt;script src=&quot;../js/sugar.js&quot;&gt;&lt;/script&gt;
174 &lt;script src=&quot;../js/parsers/parser-date.js&quot;&gt;&lt;/script&gt;</pre>
175 </div>
176
177 <h1>Javascript</h1>
178 <div id="javascript">
179 <pre class="prettyprint lang-javascript"></pre>
180 </div>
181
182 <h1>HTML</h1>
183 <div id="html">
184 <pre class="prettyprint lang-html"></pre>
185 </div>
186
187 <div class="next-up">
188 <hr />
189 Next up: <a href="example-widget-filter.html">Applying the filter widget &rsaquo;&rsaquo;</a>
190 </div>
191
192 </div>
193
194 <style>
195 .result, .tdy { color: red; }
196 .params { font-size: 0.8em; }
197 </style>
198 <script>
199 $(function() {
200 var tdy = $('.tdy'), // two digit year
201 a = $('.result'), // answer
202 r = $('.range'), // range
203 c = $('.current'), // current year
204 y = new Date().getFullYear();
205
206 tdy.val( (y + 20).toString().slice(-2) ); // use this year + 20
207 c.val( y );
208
209 $('input').on('change', function() {
210 var y = parseInt(tdy.val(), 10),
211 result = 1900 + y,
212 range = parseInt(r.val(), 10);
213 if (y < 10) { tdy.val('0' + y); }
214 y = parseInt(c.val(), 10);
215 while (y - result > range) {
216 result += 100;
217 }
218 a.html(result);
219 }).change();
220
221 });
222 </script>
223
224
225 </body>
226 </html>