mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Add ability to now macro to return same UTC string used in date fields (#2884)
* Add ability to now macro to return same UTC string used in the modified and created fields.
* Revert "Add ability to now macro to return same UTC string used in the modified and created fields."
This reverts commit 7b6ad7db4a
.
* Mods to formatDateString to adjust displayed date to UTC for [UTC]
format. Corresponding doc changes, and optimization for special
case.
This commit is contained in:
parent
1919f0e9b0
commit
4db950cc45
@ -267,6 +267,9 @@ exports.formatDateString = function(date,template) {
|
||||
[/^0ss/, function() {
|
||||
return $tw.utils.pad(date.getSeconds());
|
||||
}],
|
||||
[/^0XXX/, function() {
|
||||
return $tw.utils.pad(date.getMilliseconds());
|
||||
}],
|
||||
[/^0DD/, function() {
|
||||
return $tw.utils.pad(date.getDate());
|
||||
}],
|
||||
@ -308,6 +311,9 @@ exports.formatDateString = function(date,template) {
|
||||
[/^ss/, function() {
|
||||
return date.getSeconds();
|
||||
}],
|
||||
[/^XXX/, function() {
|
||||
return date.getMilliseconds();
|
||||
}],
|
||||
[/^[AP]M/, function() {
|
||||
return $tw.utils.getAmPm(date).toUpperCase();
|
||||
}],
|
||||
@ -324,6 +330,16 @@ exports.formatDateString = function(date,template) {
|
||||
return $tw.utils.pad(date.getFullYear() - 2000);
|
||||
}]
|
||||
];
|
||||
// If the user wants everything in UTC, shift the datestamp
|
||||
// Optimize for format string that essentially means
|
||||
// 'return raw UTC (tiddlywiki style) date string.'
|
||||
if(t.indexOf("[UTC]") == 0 ) {
|
||||
if(t == "[UTC]YYYY0MM0DD0hh0mm0ssXXX")
|
||||
return $tw.utils.stringifyDate(new Date());
|
||||
var offset = date.getTimezoneOffset() ; // in minutes
|
||||
date = new Date(date.getTime()+offset*60*1000) ;
|
||||
t = t.substr(5) ;
|
||||
}
|
||||
while(t.length){
|
||||
var matchString = "";
|
||||
$tw.utils.each(matches, function(m) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
created: 20140418142957325
|
||||
modified: 20140912145809035
|
||||
modified: 20170630223008226
|
||||
tags: Features
|
||||
title: DateFormat
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -30,10 +30,13 @@ The ViewWidget accepts a `template` attribute that allows the format of date val
|
||||
|`0mm` |Minutes with leading zero |
|
||||
|`ss` |Seconds |
|
||||
|`0ss` |Seconds with leading zero |
|
||||
|`XXX` |Milliseconds |
|
||||
|`0XXX` |Milliseconds with leading zero |
|
||||
|`am` or `pm` |Lower case AM/PM indicator |
|
||||
|`AM` or `PM` |Upper case AM/PM indicator |
|
||||
|`TZD` |Timezone offset |
|
||||
|`\x` |Used to escape a character that would otherwise have special meaning |
|
||||
|`[UTC]`|Time-shift the represented date to UTC. Must be at very start of format string|
|
||||
|
||||
Note that other text is passed through unchanged, allowing commas, colons or other separators to be used.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
caption: now
|
||||
created: 20141008141616791
|
||||
modified: 20150221170300000
|
||||
modified: 20170630223406157
|
||||
tags: Macros [[Core Macros]]
|
||||
title: now Macro
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -14,4 +14,7 @@ The value doesn't update automatically, like a ticking clock. It updates wheneve
|
||||
;format
|
||||
: A string specifying the desired [[format|DateFormat]], defaulting to `0hh:0mm, DDth MMM YYYY`
|
||||
|
||||
''Note'': The format string `[UTC]YYYY0MM0DD0hh0mm0ssXXX` will return a date string representing the UTC time-stamp as it is used in the ~TiddlyWiki `created` and `modified` time-stamp fields.
|
||||
|
||||
|
||||
<<.macro-examples "now">>
|
||||
|
Loading…
Reference in New Issue
Block a user