Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10952 > unrolled thread
| Started by | "Hans Michel" <hmichel@cox.net> |
|---|---|
| First post | 2012-07-16 09:01 +0000 |
| Last post | 2012-07-18 05:37 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: IsoWeek Function "Hans Michel" <hmichel@cox.net> - 2012-07-16 09:01 +0000
Re: IsoWeek Function Murta <rodrigomurtax@gmail.com> - 2012-07-17 05:35 +0000
Re: IsoWeek Function "Hans Michel" <hmichel@cox.net> - 2012-07-18 05:37 +0000
| From | "Hans Michel" <hmichel@cox.net> |
|---|---|
| Date | 2012-07-16 09:01 +0000 |
| Subject | Re: IsoWeek Function |
| Message-ID | <ju0l8s$l00$1@smc.vnet.net> |
See:
http://mathematica.stackexchange.com/questions/4551/determining-the-week-of-
a-year-from-a-given-date
https://groups.google.com/forum/?hl=bn&fromgroups#!topic/comp.soft-sys.math.
mathematica/PbwD8fETs3A
There maybe even easier ways to implement this functionality.
http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
Hans
-----Original Message-----
From: Murta [mailto:rodrigomurtax@gmail.com]
Sent: Sunday, July 15, 2012 10:44 PM
Subject: IsoWeek Function
Hi All
Please, in Mathematica 9 include IsoWeek functions in the standard into
DateList and DateString. It would be simple if we have a "ISOWeekYear" and
"ISOWeekNumber" as in Oracle and SQL.
Today it's necessary to implemente our own functions, and I get very slow
performance results.
I use that to take ISO Week numbers:
ISOWeek[x_]:=Module[{baseDate,year454,weekNames,numWeek},
weekNames={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Satu
rday"};
year454=First@DateList@DatePlus[x,-Position[weekNames,DateString[DatePlus[x,
-1],{"DayName"}],1][[1,1]]+4];
baseDate={year454,1,3};
numWeek=IntegerPart[1/7(DateDifference[baseDate,x]+Position[weekNames,DateSt
ring[baseDate,{"DayName"}],1][[1,1]]+5)];
{year454,numWeek}
]
Example
ISOWeek["20120101"]
{2011,52}
I tried to compile it, but with no sucess..
Any clue?
Another tip for the developer is create an string "WeekDayNumber", that can
return the week day number. Today we have option just to names.
tks in advance
Murta
[toc] | [next] | [standalone]
| From | Murta <rodrigomurtax@gmail.com> |
|---|---|
| Date | 2012-07-17 05:35 +0000 |
| Message-ID | <ju2ti5$s6c$1@smc.vnet.net> |
| In reply to | #10952 |
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...
[toc] | [prev] | [next] | [standalone]
| From | "Hans Michel" <hmichel@cox.net> |
|---|---|
| Date | 2012-07-18 05:37 +0000 |
| Message-ID | <ju5i2k$3q8$1@smc.vnet.net> |
| In reply to | #10952 |
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...
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web