<now WW>> is lying?

234 views
Skip to first unread message

Philippe Le Toquin

unread,
Nov 10, 2016, 6:31:37 PM11/10/16
to TiddlyWiki
Hello,

Something strange suddenly happened.

I am using <now  WW> to get the current week number. Until a few minutes ago it was all good and telling that the week number is 45

but then without any warning it now tells me we are week 46!

Add we been on a Sunday night I might accept that getting closer to midnight it is possible that UTC is causing that issue BUT we are Thursday!

Philippe

Del Vee

unread,
Nov 11, 2016, 12:07:05 AM11/11/16
to TiddlyWiki
Hi

For me < < now WW > > return 45

I hope that help hou

Jed Carty

unread,
Nov 11, 2016, 3:55:05 AM11/11/16
to TiddlyWiki
The now macro uses the built-in javascript date object. This means that errors like that almost certainly come from your browsers javascript implementation, not from the tiddlywiki side. So what browser are you using? I think that the only fix we could do on this is detect the browser and if there is some consistent error on one browser we can have the macro adjust in those browsers.

Jeremy Ruston

unread,
Nov 11, 2016, 4:10:12 AM11/11/16
to tiddl...@googlegroups.com
Hi Jed, Philippe,

The now macro uses the built-in javascript date object.

In fact, the ISO 8601 week number calculations are part of utils.js:


As I recall, the logic was derived from an example like this:


It’s entirely possible that there is a bug in the implementation, or that 8601 itself contains unexpected behaviours.

Best wishes

Jeremy

This means that errors like that almost certainly come from your browsers javascript implementation, not from the tiddlywiki side. So what browser are you using? I think that the only fix we could do on this is detect the browser and if there is some consistent error on one browser we can have the macro adjust in those browsers.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e225a4a2-5e43-4ea4-bb2e-ad70761984ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dragon Cotterill

unread,
Nov 11, 2016, 4:45:08 AM11/11/16
to TiddlyWiki
On Friday, 11 November 2016 09:10:12 UTC, Jeremy Ruston wrote:
It’s entirely possible that there is a bug in the implementation, or that 8601 itself contains unexpected behaviours.


Yes.. "Unexpected".

Actually the way week numbers are calculated around the world changes. https://en.wikipedia.org/wiki/Week#Week_numbering
ISO8601 starts the week on a Monday. America starts it on a Sunday. This throws spanners in the works depending on Time Zones, Daylight Savings etc. Considering North America went through it's daylight savings shift, this may have had an impact.

Philippe Le Toquin

unread,
Nov 11, 2016, 4:57:18 AM11/11/16
to TiddlyWiki
Hi all,

I am using Firefox 49.0.2 on Ubuntu

What is very strange is that this morning we are back to week 45. if seems related to the time it happened (it was around 23:00 UK time).
I had been working on my project for some time in the evening and it was properly reporting week number 45 until then.

If I am still scratching my head trying to debug my TW5 project tonight I will keep an eye on it.

If it happens again I guess I will have to make sure I don't enter my daily records around that time at night

Philippe

Philippe Le Toquin

unread,
Nov 11, 2016, 6:15:48 PM11/11/16
to TiddlyWiki

It is doing it again.

There is definitely something that occurs around 23:00 UK time

Mark S.

unread,
Nov 11, 2016, 10:40:26 PM11/11/16
to TiddlyWiki
The problem with your screen shot is that it doesn't show the date/time. Perhaps the next time this occurs, you could also drop in <<now>> and capture what that says as well. Also, if you have some other browser on Ubuntu, try running <<now>> and <<now WW>> on them. Also, just as a control, if you have access to a  Windows or Mac machine, maybe try seeing if (at the same time) whether <<now>> and <<now WW>>  run differently on those platforms at the same time.

All this data might help triangulate whether it's something particular to your set up, your browser, or your platform.

Good luck!
Mark

Riz

unread,
Nov 12, 2016, 9:45:03 AM11/12/16
to TiddlyWiki



Yours seems like an interesting set up. If you haven't entered much personal data already, care to share? May be it will also enable us to see if the problem persists in another set up in another part of the world.

Philippe Le Toquin

unread,
Nov 12, 2016, 11:16:59 AM11/12/16
to TiddlyWiki
By set up you mean the tiddlywiki I am setting up? if it is then my intention was always to share it back once I am happy with it but as you can see from my multiple message I am having some issue with putting what's in my head in code

Basically I am a homebaker and to keep track of what I am doing I was looking for a program. Somehow I rediscovered TW and thought it would be a goo idea to use it

It is by no mean finished but I am at a point where my coding skills are failing. If you want I can create a new post and share a sanitised version of my file.

Thanks for your interest Riz

Philippe Le Toquin

unread,
Nov 12, 2016, 6:15:28 PM11/12/16
to TiddlyWiki

Hello,

So here is some fresh pictures before 23:00 (correct week displayed) and after 23:00 (wrong week). I still don't get it why the week would change lie that midweek :(

I don't have access to Windows or Mac. I do have an Android tablet and have the app AndTidWiki on it. The problem is the same. But then Android is linux so if it is a linux issue it will be there as well I guess.

Philippe Le Toquin

unread,
Nov 12, 2016, 7:10:44 PM11/12/16
to TiddlyWiki
It is now past midnight and we are back to week 45. Sorry no screenshot as I don't know how to do it on a tablet

Mark S.

unread,
Nov 12, 2016, 8:16:19 PM11/12/16
to TiddlyWiki
Since I never stay up until these un-Thorly hours, I played with my system clock, moving it to a time between 11pm and 12am. Sure enough, the week jumps to 46. This was on Firefox under Windows 7. I tested again with Chrome, and the same thing happened.

So it appears that is a real bug, and anyone can replicate it by setting their clock to some time between 11pm and 12am, creating a tiddler with <<now WW>>, and refreshing the tiddler.

Maybe some code warriors can wade in now ...

Mark

Philippe Le Toquin

unread,
Nov 13, 2016, 3:55:32 AM11/13/16
to TiddlyWiki
Glad to see it is not just me.

As for un-Thorly hours well that is the only time I have left to myself once the kids are in bed. That and I like to find bugs at 23:00

Jeremy Ruston

unread,
Nov 13, 2016, 4:03:11 AM11/13/16
to tiddl...@googlegroups.com
Hi Philippe, Mark,

I suspect that the problem here may be related to TiddlyWiki’s unfortunate handling of timezones. Basically, all dates are stored in UTC time, which is then automatically adjusted by the prevailing timezone to local time when the tiddler is loaded.


Pending some sort of fix in the core, there may well be workarounds that you can use for the week generation (eg, a tiny custom JS macro to generate a corrected week number).

Best wishes

Jeremy

-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Philippe Le Toquin

unread,
Nov 13, 2016, 4:08:48 AM11/13/16
to TiddlyWiki
I can understand that Jeremy but what I find strange is that it happens every night. If it was on Sunday night I would agree that it is an unfortunate side issue of using timezone but on a week day?

It doesn't annoy me more than that and I can live with it (there are bigger issue with my coding!). I can definitely wait for a fix if/when it comes.

Jeremy Ruston

unread,
Nov 13, 2016, 4:49:48 AM11/13/16
to tiddl...@googlegroups.com
Hi Philippe

I think the reason it happens at 23h00 local time might be because that's when the corresponding UTC time flips into the next day.

Best wishes

Jeremy

--
Jeremy Ruston

PMario

unread,
Nov 13, 2016, 9:42:50 AM11/13/16
to TiddlyWiki
On Sunday, November 13, 2016 at 10:49:48 AM UTC+1, Jeremy Ruston wrote:
I think the reason it happens at 23h00 local time might be because that's when the corresponding UTC time flips into the next day.

I think I found the problem. Some more tests needed.

imo it's: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/utils/utils.js#L361  that causes the problem
especially: new Date(dt.getFullYear(),0,1) + 3600000  creates nonsense if you try it in the console.

IMO getWeek needs too look like this:

exports.getWeek = function(date) {
    var dt = new Date(date.getTime());
    var d = dt.getDay();
    if(d === 0) {
        d = 7; // JavaScript Sun=0, ISO Sun=7
    }
    dt.setTime(dt.getTime() + (4 - d) * 86400000);// shift day to Thurs of same week to calculate weekNo
    var x = new Date(dt.getFullYear(),0,1);
    var n = Math.floor((dt.getTime() - x.getTime()) / 86400000);
    return Math.floor(n / 7) + 1;
};

------------------

Some more TW code to play with Week display, without waiting till 23:00 your time :)

<$view field="created" format=date template="YYYY-MM-DD 0hh:0mm:0ss. -- kw: WW -- Z TZD"/><br>

<$view field="time" format=date template="YYYY-MM-DD 0hh:0mm:0ss. -- kw: WW -- Z TZD"/>


Add a field named: time to your tiddler eg: time: 20161112225959

have fun!
mario
PS: I'll create a PR after testing the fix.

Philippe Le Toquin

unread,
Nov 13, 2016, 10:20:37 AM11/13/16
to TiddlyWiki
It seems indeed to be better. I replaced the getWeek function with your update. After a reload of the page and using your test code I get the correct week 45 even after 23:00

It also switch to week 46 if I enter a date for next week ;)

As you say more test is required to be sure that it doesn't break something else.

That's what I call reactivity!!

Philippe

PMario

unread,
Nov 13, 2016, 5:59:49 PM11/13/16
to TiddlyWiki
On Sunday, November 13, 2016 at 4:20:37 PM UTC+1, Philippe Le Toquin wrote:
As you say more test is required to be sure that it doesn't break something else.

That's what I call reactivity!!
 
There are some tests in TW for utils.js, but it seems they are not testing for edge cases. eg: switch from week 52to53to1 and so on. I'll add some of them. And create a PR if it seems to work :)

have fun!
mario

PMario

unread,
Nov 13, 2016, 7:18:54 PM11/13/16
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages