MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: IsoWeek Function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127334] Re: IsoWeek Function
  • From: "Hans Michel" <hmichel at cox.net>
  • Date: Wed, 18 Jul 2012 01:36:51 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20120716034417.DD63E6857@smc.vnet.net> <ju0l8s$l00$1@smc.vnet.net> <20120717053245.E06366884@smc.vnet.net>

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 at gmail.com] 
Sent: Tuesday, July 17, 2012 12:33 AM
To: mathgroup at smc.vnet.net
Subject: [mg127334] 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...




  • Prev by Date: Plotting: how does one reverse the time axis tick mark values?
  • Next by Date: Re: Differential Equation: Not getting result
  • Previous by thread: Re: IsoWeek Function
  • Next by thread: DateList