Date in custom field is one day off

132 views
Skip to first unread message

Damon Pritchett

unread,
Jan 31, 2019, 7:10:07 PM1/31/19
to TiddlyWiki
Hi all,

I've created a custom field in my TW that I use to store a date. I store the date in this fashion 20190131 (if I uses dashes between the year, month and day, the date is way off). In a table cell where I want the date to appear, I've entered <$view field="customdate" format="date" template="MMM DD, YYYY"/>. When the date is displayed, it is one day off (less). If I put an 8 afterwards (201901318), then the date in the table is displayed correctly. Is this a bug or something I'm doing wrong?

Thanks,

Damon

S. S.

unread,
Jan 31, 2019, 7:45:44 PM1/31/19
to TiddlyWiki
Damon,

On the tiddlywiki.com website, the tiddler : Date Fields : tells us:

To avoid problems arising from differences of time zone, TiddlyWiki always uses UTC.

The tiddler : DateFormat : tells us:

[UTC]    Time-shift the represented date to UTC. Must be at very start of format string.
 
UTC is Coordinated Universal Time - so a time zone offset is needed for where you are.
The extra 8 you used signifies HOURS. Instead this may work:

<$view field="customdate" format="date" template="[UTC]MMM DD, YYYY"/>

Hope that helps.

Mark S.

unread,
Jan 31, 2019, 7:46:12 PM1/31/19
to TiddlyWiki
The view field expects that the date is stored as UTC. When you put the date in by hand, then it's assuming that you mean (if I recall correctly) UTC 2019-1-31 at midnight. The view template then translates that into your local time, which might even be on a different day, depending your timezone.

-- Mark

TonyM

unread,
Jan 31, 2019, 7:52:13 PM1/31/19
to TiddlyWiki
[UTC]Time-shift the represented date to UTC. Must be at very start of format string
So Try
<$view field="customdate" format="date" template="[UTC]MMM DD, YYYY"/>

Damon Pritchett

unread,
Jan 31, 2019, 9:05:43 PM1/31/19
to TiddlyWiki
All,

I tried as suggested and that did help to some degree. Since my TW is being used for a history project that I'm doing, I have many 19th century dates. That fix does not work for dates earlier than the year 1884 for some reason. I get very odd behavior when I type a years of 1883 or earlier. It seems to depend on how I type it in whether it's correct or not. Any thoughts on this?

Thanks once again,

Damon

Damon Pritchett

unread,
Jan 31, 2019, 9:11:32 PM1/31/19
to TiddlyWiki
Sidenote - 1884 happens to be the year that the Greenwich Meridian was chosen as the Prime Meridian. Coincidence?

Damon

Mohammad

unread,
Jan 31, 2019, 10:20:11 PM1/31/19
to TiddlyWiki
Added to TW-Scripts.

TonyM

unread,
Jan 31, 2019, 11:38:35 PM1/31/19
to TiddlyWiki
Damon,

I am sorry I do not know the answer to this. Either the plugin or the moment library may not take proper account for this.

However perhaps you can explain what you are doing in your wiki to set and review the dates, where is it going wrong?

What of out suggestions did you use?, how are you selecting the date?

Regards
Tony

Damon Pritchett

unread,
Jan 31, 2019, 11:47:53 PM1/31/19
to TiddlyWiki
Tony

I tried putting [UTC] in the date format as you suggested. This worked great for years 1884 and higher. I’ve created a field called charterdate and am using that in the field area of the view widget. I’ve entered the date in the field as 18710215. That’s the actual date I’m working with (Feb. 15,1871).

Damon

Damon Pritchett

unread,
Jan 31, 2019, 11:53:40 PM1/31/19
to TiddlyWiki
I should also say that the view widget is within a cell of an html table.

TonyM

unread,
Feb 1, 2019, 12:08:16 AM2/1/19
to TiddlyWiki
Damon,

Since you are entering the data manually perhaps you can do one of the following
  1. Have separate fields for year, month and day and do your own Date formatting {{!!day))-{{!!month))-{{!!Year}}
  2. Find away to split you date into something like number 1 then do the same.
This is clearly a workaround because UTC fails back then. PS are the old dates correct when not specifying UTC?

Maybe other "Historians" will notice this thread.

Tonyu

Damon Pritchett

unread,
Feb 1, 2019, 12:22:10 PM2/1/19
to TiddlyWiki
Tony,

I'll give your suggestion a try and let you know.

In answer to your question, no the old dates were not correct when not specifying UTC. All dates were incorrect before specifying UTC and only dates 1884 and sooner were correct when specifying UTC.

Damon

Damon Pritchett

unread,
Feb 1, 2019, 12:51:53 PM2/1/19
to TiddlyWiki
So I found that separating the year, month and day doesn't really do what I want. It's much easier to treat the field as text and then enter 1871-02-15. I'll still be able to sort that way. I'm still hoping that someone will see this thread and have a fix or work around. Is this a bug?

Damon


On Thursday, January 31, 2019 at 10:08:16 PM UTC-7, TonyM wrote:

Mark S.

unread,
Feb 1, 2019, 2:21:45 PM2/1/19
to TiddlyWiki
You might explain what your requirements will be. That is, how will you be using the dates? If all you need are sortable dates, then rolling your own like 2018-02-01 should be fine as long as you're consistent. But if you need to see "all historic events that occurred within 10 days of each other" or "all historic dates that occurred on a Friday" then it might require a bit more inquiry.

-- Mark

Damon Pritchett

unread,
Feb 1, 2019, 2:42:50 PM2/1/19
to TiddlyWiki
Mark,

In reality, all I really need is sortability and the filtering down to the year. So the roll your own method will suit those needs. However, what I’d like to be able to do is to display the dates with words for the months rather than numbers without having to do acrobatics to do so. Maybe that’s not currently possible.

Damon

Mark S.

unread,
Feb 1, 2019, 4:43:05 PM2/1/19
to TiddlyWiki
Here's some acrobatics:

\define mo-str(date)
<$list filter="[[$date$]splitbefore[-]]" variable=y >
<$list filter="[[$date$]removeprefix<y>splitbefore[-]removesuffix[-]]" variable=m>
<$list filter="[[data-months]getindex<m>]"/>
</$list>
</
$list>
\end

<$macrocall $name="mo-str" date={{!!mydate}}/>

Assuming date is exactly formatted like 2018-01-02 and

Where
"data-months" is  a data dictionary mapping numbers 01 ... 12 to months Jan... Dec, or whatever language you prefer.

Have fun,
-- Mark

Damon Pritchett

unread,
Feb 1, 2019, 6:49:41 PM2/1/19
to TiddlyWiki
Hey Mark,

Acrobatics for me and child's play for, but I'm learning. Tried you're code with a little modification and it outputs exactly what I want. Here's what I did:

\define date-str(date)
<$list filter="[[$date$]splitbefore[-]]" variable=x >
<$list filter="[[$date$]removeprefix<x>splitbefore[-]removesuffix[-]]" variable=m>

<$list filter="[[data-months]getindex<m>]" />
<$list filter="[[$date$]splitbefore[-]removesuffix[-]]" variable=y >
<$list filter="[[$date$]removeprefix<x>removeprefix<m>removeprefix[-]]" variable=d >
<<d>>, <<y>>
</$list>
</
$list>
</$list>
</
$list>
\end


I did change some of the variable names a bit. The last question I have is this. The month comes out as a missing tiddler. Is there a way that I can just have that be text?

Thanks again,

Damon

Mark S.

unread,
Feb 1, 2019, 7:10:52 PM2/1/19
to TiddlyWiki
To eliminate the "links", instead of <<d>> and <<y>>, try <$text text=<<d>>/> .

-- Mark

Damon Pritchett

unread,
Feb 1, 2019, 7:12:42 PM2/1/19
to TiddlyWiki
Mark,

The problem is nor d and y, it’s m. Even before I made my changes the month was not text.

Damon

Mark S.

unread,
Feb 1, 2019, 8:16:16 PM2/1/19
to TiddlyWiki
\define date-str(date)
<$list filter="[[$date$]splitbefore[-]]" variable=x >
<$list filter="[[$date$]removeprefix<x>splitbefore[-]removesuffix[-]]" variable=m>

<$list filter="[[data-months]getindex<m>]" variable="mname">

<$list filter="[[$date$]splitbefore[-]removesuffix[-]]" variable=y >
<$list filter="[[$date$]removeprefix<x>removeprefix<m>removeprefix[-]]" variable=d >
<<mname>> <<d>>, <<y>>
</$list>
</
$list>
</$list>
</
$list>
</$list>
\end


The problem was this line:

<$list filter="[[data-months]getindex<m>]" />

If you don't specify a template or a variable name, TW uses a default template which makes the output of a list widget a series of links.

HTH
-- Mark

Damon Pritchett

unread,
Feb 1, 2019, 8:29:13 PM2/1/19
to TiddlyWiki
Thanks Mark,

That worked perfectly. I had tried something similar, but some of the nuances messed me up I guess. Why does mname need quotes, but m does not? Also, what determines whether or not there is a /  before the > for the list widget versus having </$list>? Or are these two related questions?

Thanks,

Damon
Reply all
Reply to author
Forward
0 new messages