For instance this week is : "6w14".
Now I enter them each time manually, but I'd like a script or macro in
which you input Y M D, and which outputs the computed week : "14", or
better "6w14" (for today)
Here is the shorter algo I found :
function getWeekNumber(month, day, year)
{
var now = new Date(year, month, day + 1);
var then = new Date(year, 0, 1);
var firstDay = new Date(year, 0, 1);
var compensation = firstDay.getDay() + 3;
return Math.round((((now - then) / 86400000) + compensation) / 7);
}
Thanks for help :)
Jacques
I still miss something, as my result is : "6sNaN"
Here was my try :
config.macros.weekNb = {};
config.macros.weekNb.handler = function
(place,macroName,params,wikifier,paramString,tiddler) {
wikify("6s" + getWeekNumber(), place);
}
function getWeekNumber(month, day, year)
{
var now = new Date(year, month, day + 1);
var then = new Date(year, 0, 1);
var firstDay = new Date(year, 0, 1);
var compensation = firstDay.getDay() + 3;
return Math.round((((now - then) / 86400000) + compensation) / 7);
}
getDay() has to be defined or has another name in TW or Dateplugin ?
Question :
Is there a thread, or a tutorial where macro parameters are explained :
I copy without really understanding this line :
function (place,macroName,params,wikifier,paramString,tiddler) { ...
Thanks,
Jacques
But, it appears that there's several competing week numbering systems:
http://www.rondebruin.nl/weeknumber.htm
I'd be interested in a concise, flexible implementation of
Date.prototype.getWeek() that could cope with all these various
schemes.
Cheers
Jeremy.
--
Jeremy Ruston
mailto:jer...@osmosoft.com
http://www.tiddlywiki.com
I recall grappling with this mess around 1991 or so. When I saw this
post I figured there wasn't much point in responding since by now,
surely, "the world" would have got its act together and fixed it.
Silly me.
I'd propose that core TW implement the ISO8601 and stop there.
core.getWeekNo (or whatever) can be overidden/hijacked on a case by
case (TW by TW) basis.
I can't imagine a situation where one TW would need more than one
standard for week numbers (except, perhaps, in that rare circumstance
where its purpose was to educate us as to the weirdness of dates in
general and the need to convert between them).
In fact, it's my opinion that core systems - I include TW here -
should return ISODATE8601
(http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html)
and let "flavour" plugins deal with the rest.
just my 0.02
russ
Cheers
Jeremy.
Thanks Simon,
I still miss something, as my result is : "6sNaN"
Here was my try :
config.macros.weekNb = {};
config.macros.weekNb.handler = function
(place,macroName,params,wikifier,paramString,tiddler) {
wikify("6s" + getWeekNumber(), place);
}