Refine date format tokens for weekday number, and add support for day of year

See discussion at https://groups.google.com/g/tiddlywiki/c/tf23ByDXzxM/m/5Wx7PV36AwAJ
sort-optimisations
jeremy@jermolene.com 2021-09-17 14:52:08 +01:00
rodzic de33b365ae
commit f223896c26
2 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -383,12 +383,18 @@ exports.formatDateString = function(date,template) {
[/^0WW/, function() { [/^0WW/, function() {
return $tw.utils.pad($tw.utils.getWeek(date)); return $tw.utils.pad($tw.utils.getWeek(date));
}], }],
[/^0dddd/, function() {
return $tw.utils.pad(Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24),3);
}],
[/^dddd/, function() { [/^dddd/, function() {
return [7,1,2,3,4,5,6][date.getDay()]; return Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24);
}], }],
[/^ddd/, function() { [/^ddd/, function() {
return $tw.language.getString("Date/Short/Day/" + date.getDay()); return $tw.language.getString("Date/Short/Day/" + date.getDay());
}], }],
[/^dd/, function() {
return [7,1,2,3,4,5,6][date.getDay()];
}],
[/^mmm/, function() { [/^mmm/, function() {
return $tw.language.getString("Date/Short/Month/" + (date.getMonth() + 1)); return $tw.language.getString("Date/Short/Month/" + (date.getMonth() + 1));
}], }],

Wyświetl plik

@ -7,9 +7,11 @@ type: text/vnd.tiddlywiki
When used to display date values (with the `format` attribute set to ''date''), the ViewWidget accepts a `template` attribute that allows the format of the date values to be specified. The format string is processed with the following substitutions: When used to display date values (with the `format` attribute set to ''date''), the ViewWidget accepts a `template` attribute that allows the format of the date values to be specified. The format string is processed with the following substitutions:
|!Token |!Substituted Value | |!Token |!Substituted Value |
|`dddd` |Day of year (1 to 365, or 366 for leap years) |
|`0dddd` |Zero padded day of year (001 to 365, or 366 for leap years)
|`DDD` |Day of week in full (eg, "Monday") | |`DDD` |Day of week in full (eg, "Monday") |
|`ddd` |Short day of week (eg, "Mon") | |`ddd` |Short day of week (eg, "Mon") |
|`dddd` |<<.from-version "5.2.0">> Weekday number from 1 through 7, beginning with Monday and ending with Sunday | |`dd` |<<.from-version "5.2.0">> Weekday number from 1 through 7, beginning with Monday and ending with Sunday |
|`DD` |Day of month | |`DD` |Day of month |
|`0DD` |Adds a leading zero | |`0DD` |Adds a leading zero |
|`DDth` |Adds a suffix | |`DDth` |Adds a suffix |