Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: IsoWeek Function
Replies: 4   Last Post: Jul 18, 2012 1:37 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
hmichel@cox.net

Posts: 122
Registered: 1/29/05
Re: IsoWeek Function
Posted: Jul 18, 2012 1:37 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

If I recall your ISOWeek function takes in a datestring in your example

ISOWeek["20120101"]

I believe you may get some speed gains by not letting Mathematica do the
date format translation.

Write you own translation if the date format is also in ISO to Mathematica
date list form.

"20120101" -> {2012,1,1}

Hans

-----Original Message-----
From: Murta [mailto:rodrigomurtax@gmail.com]
Sent: Tuesday, July 17, 2012 12:33 AM
Subject: Re: IsoWeek Function

Tks for your attention
I have made some progress, but not enough:

below there is one fast way to get weekDay

weekDayC = Compile[{{ano, _Integer}, {m, _Integer}, {d, _Integer}}
, Module[{t, y = ano},
(*2 for Monday*)
t = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= Boole[m < 3];
Mod[y + IntegerPart[y/4.] - IntegerPart[y/100.] +
IntegerPart[y/400.] + t[[m]] + d + 1, 7, 1]
]
]


I used it in my ISOWeek like this

ISOWeekX2[x_] := Module[{baseDate, year454, weekNames, numWeek},
year454 = First@DatePlus[x, -Mod[weekDayC @@ x - 1, 7, 1] + 4];
baseDate = {year454, 1, 3};
numWeek =
IntegerPart[
1/7 (DateDifference[baseDate, x] + weekDayC @@ baseDate + 5)];
{year454, numWeek}
]

But the there are 2 another slow parts, that are DateDifference and
DataPlus. But to get rid of that that is a lot of job..
Native functions would be great...





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.