comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: days of the week
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: days of the week [message #29836] Thu, 21 March 2002 09:01 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Mark Hadfield" <m.hadfield@niwa.co.nz> writes:

> "Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
> news:ong02v434v.fsf@cow.physics.wisc.edu...
>
>> P.S. I think the built-in JULDAY function is the one of the most
>> dangerous function I have ever seen. It measures *calendar dates*
>> from *noon* by gosh!
>
> I couldn't agree more.
>
>> It also doesn't handle fractional days...
>
> Not true in recent versions...
>
> IDL> print, julday(03,21,2002)
> 2452355
> IDL> print, julday(03,21,2002,10,23,30)
> 2452354.9
>
> But that weird argument order (month, day, year, ...) is what I
> *really* hate.

That is true, and the irony here is that JULDAY came from Numerical
Recipes, and other criticisms about code quality aside, those NR guys
are *astronomers* gosh darnit!

The following is totally unintuitive to me:

IDL> print, julday(3d,21d,2002d), format='(D30.3)'
2452355.000
;; Now, how about "one second" later
IDL> print, julday(3d,21d,2002d,00d,00d,01d), format='(D30.3)'
2452354.500

It's because in one case the calendar dates are measured from noon,
and in the other they are measured from midnight.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: days of the week [message #29837 is a reply to message #29836] Thu, 21 March 2002 09:01 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:

> Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
>
>> I think you mean an "astronomical" or "celestial" event, and it
>> actually happens today at 19:16:08 UTC.
>
> Oh, my gosh. I didn't even think of that. I can feel the
> depression lifting already. :-)

For us, at least the sun came out for the first time in about a week.
Drought notwithstanding, that's a nice change.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: days of the week [message #29841 is a reply to message #29836] Thu, 21 March 2002 07:34 Go to previous messageGo to next message
Doug Rowland is currently offline  Doug Rowland
Messages: 12
Registered: March 2002
Junior Member
> Not true in recent versions...
>
> IDL> print, julday(03,21,2002)
> 2452355
> IDL> print, julday(03,21,2002,10,23,30)
> 2452354.9
>
> But that weird argument order (month, day, year, ...) is what I
> *really* hate.
>
> --
> Mark Hadfield
> m.hadfield@niwa.co.nz Ka puwaha et tai nei
> http://katipo.niwa.co.nz/~hadfield Hoea tatou
> National Institute for Water and Atmospheric Research (NIWA)


Ah yes, from the country that brought you Tab soda and George W. Bush...
At least IDL doesn't force everything to be in imperial units.

--
Doug Rowland
rowland@fields.space.umn.edu
School of Physics and Astronomy
University of Minnesota
Re: days of the week [message #29849 is a reply to message #29841] Thu, 21 March 2002 03:21 Go to previous messageGo to next message
the_cacc is currently offline  the_cacc
Messages: 104
Registered: October 2001
Senior Member
David Fanning <david@dfanning.com> wrote in message news:<MPG.17025cedc0db98d798983c@news.frii.com>...
>
> P.S. Sorry for the FOR loop. I was in a hurry. :-(
>

Tsk, according to my timings that FOR loop is costing us 0.0009 seconds.
Maybe OK for some, but what if ya gots to know the day *now*? Maybe also
consider using IntArr(7,/NOZERO)? ;)
Re: days of the week [message #29857 is a reply to message #29849] Wed, 20 March 2002 14:20 Go to previous messageGo to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"Bastienne Schneiter" <b.schneiter@meteonews.ch> wrote in message
news:c3ea865f.0203200659.62bcaed9@posting.google.com...

> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this
> date correspond (MON, TUE etc). Does anybody know how to determine
> the day of the week for a given date?

Several solutions to your last question have already been offered, but
if you just want to *show* the day of the week you can use IDL's
calendar format specifiers.

IDL> print, 'Today is', systime(/JULIAN), FORMAT='(A,X,C(CDwA0))'
Today is Thursday

--
Mark Hadfield
m.hadfield@niwa.co.nz Ka puwaha et tai nei
http://katipo.niwa.co.nz/~hadfield Hoea tatou
National Institute for Water and Atmospheric Research (NIWA)
Re: days of the week [message #29859 is a reply to message #29857] Wed, 20 March 2002 14:26 Go to previous messageGo to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
news:ong02v434v.fsf@cow.physics.wisc.edu...

> P.S. I think the built-in JULDAY function is the one of the most
> dangerous function I have ever seen. It measures *calendar dates*
> from *noon* by gosh!

I couldn't agree more.

> It also doesn't handle fractional days...

Not true in recent versions...

IDL> print, julday(03,21,2002)
2452355
IDL> print, julday(03,21,2002,10,23,30)
2452354.9

But that weird argument order (month, day, year, ...) is what I
*really* hate.

--
Mark Hadfield
m.hadfield@niwa.co.nz Ka puwaha et tai nei
http://katipo.niwa.co.nz/~hadfield Hoea tatou
National Institute for Water and Atmospheric Research (NIWA)
Re: days of the week [message #29862 is a reply to message #29857] Wed, 20 March 2002 09:17 Go to previous messageGo to next message
Ed Wright is currently offline  Ed Wright
Messages: 39
Registered: February 1999
Member
A somewhat more versatile Day of Week function:

dow = julian_day - 7*( (julian_day + 1)/7 ) + 2

using pure integer math. The function returns a value 1 to 7 where 1
corresponds to Sunday.

As always,
Ed Wright
Re: days of the week [message #29863 is a reply to message #29862] Wed, 20 March 2002 09:42 Go to previous messageGo to next message
Randall Skelton is currently offline  Randall Skelton
Messages: 169
Registered: October 2000
Senior Member
Try the JHU/APL/S1R library at:

http://fermi.jhuapl.edu/s1r/idl/s1rlib/time/dt_tm.html

On 20 Mar 2002, Bastienne Schneiter wrote:

> Hello,
>
> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?
>
> Thank you
> Bastienne
>
Re: days of the week [message #29864 is a reply to message #29862] Wed, 20 March 2002 08:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> Weeks are always exactly seven days long.

I don't know. I've been up every night for the past three
waiting for puppies to be born. And my tennis team got
beat yesterday 3-4, losing 11-9 in a tie-breaker in the
pivotal match. It feels like this week is already 10 days
long. :-(

> P.S. I think the built-in JULDAY function is the one of the most
> dangerous function I have ever seen. It measures *calendar dates*
> from *noon* by gosh! It also doesn't handle fractional days, which is
> a pity, but thankfully there are tons of IDL Astro/JHU functions which
> overcome this.

I agree with this. Unfortunately, I learned long ago that
when posting code to the HUGE IDL newsgroup audience it is
always better to restrict yourself to the lowest common
denominator. Otherwise, you send the last 8 days of the
week writing e-mails to people asking them to *please*
consider upgrading to a version of IDL written in this
century. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: days of the week [message #29865 is a reply to message #29864] Wed, 20 March 2002 08:49 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> I think you mean an "astronomical" or "celestial" event, and it
> actually happens today at 19:16:08 UTC.

Oh, my gosh. I didn't even think of that. I can feel the
depression lifting already. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: days of the week [message #29866 is a reply to message #29865] Wed, 20 March 2002 08:25 Go to previous messageGo to next message
eddie haskell is currently offline  eddie haskell
Messages: 29
Registered: September 1998
Junior Member
> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?

David's routine does work, and just for the record, you can also use IDL's
label_date routine by throwing in a couple dummy parameters.

IDL> print, label_date(0,0,julday(11,17,2002),date_format='%W')
Sun

Cheers,
eddie
Re: days of the week [message #29867 is a reply to message #29866] Wed, 20 March 2002 08:26 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:

> Bastienne Schneiter (b.schneiter@meteonews.ch) writes:
>
>> I need to show a date in a little application. Its format is
>> YYYYMMDDHH. But I also have to show to which day of the week this date
>> correspond (MON, TUE etc).
>> Does anybody know how to determine the day of the week for a given
>> date?
>
> Here is a bonus question. What is the significance
> of a meteorological event that happens on a Thursday?

I think you mean an "astronomical" or "celestial" event, and it
actually happens today at 19:16:08 UTC.

To answer Bastienne's original question, it's actually easier to
compute the day of the week than the calendar date. That's because
there are no "leap" weekdays, or irregularly sized weeks. Weeks are
always exactly seven days long.

We know that March 24, 2002, is a Sunday. Thus, we can compute the
day of the week using the MOD function:

dayweek = (julday(month,day,year) - julday(3,24,2002)) MOD 7
dayweek = (dayweek + 7) MOD 7

Where 0 means Sunday and 6 means Saturday. The second statement is to
handle cases when DAYWEEK is negative, which happens with the MOD
function unfortunately.

Craig

P.S. I think the built-in JULDAY function is the one of the most
dangerous function I have ever seen. It measures *calendar dates*
from *noon* by gosh! It also doesn't handle fractional days, which is
a pity, but thankfully there are tons of IDL Astro/JHU functions which
overcome this.

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: days of the week [message #29868 is a reply to message #29866] Wed, 20 March 2002 07:47 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bastienne Schneiter (b.schneiter@meteonews.ch) writes:

> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?

Alright. Here is a little function that, given the
julian date, will tell you what day of the week it
is. For example, suppose you want to get married
on November 17, 2002 and the preacher asks you what
day of the week that is. You do this:

"Uh, hold-on...."

IDL> juliandate = Julday(11, 17, 2002)
IDL> Print, WhatDayIsIt(juliandate)
Sunday

"Uh, that's a Sunday, Man."

Cheers,

David

P.S. Sorry for the FOR loop. I was in a hurry. :-(

************************************************************ ************
FUNCTION WhatDayIsIt, juliandate

; Need a date? Duh...

IF N_Elements(juliandate) EQ 0 THEN $
juliandate = Systime(/Julian)

; Make a table. Use week of March 17th, 2002.

daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', $
'Thursday', 'Friday', 'Saturday']
datemod = IntArr(7)

FOR j=0,6 DO BEGIN
jdate = Julday(3, 17 + j, 2002)
datemod[j] = jdate MOD 7
ENDFOR

; Convert to day, month, year.

CalDat, juliandate, month, day, year
jdate = Julday(month, day, year)

; What day of the week is it? Return it.

index = Where(datemod EQ (jdate MOD 7))
RETURN, daysOfWeek[index]
END
************************************************************ ************

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: days of the week [message #29869 is a reply to message #29868] Wed, 20 March 2002 07:12 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bastienne Schneiter (b.schneiter@meteonews.ch) writes:

> I need to show a date in a little application. Its format is
> YYYYMMDDHH. But I also have to show to which day of the week this date
> correspond (MON, TUE etc).
> Does anybody know how to determine the day of the week for a given
> date?

Here is a bonus question. What is the significance
of a meteorological event that happens on a Thursday?

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: days of the week [message #29884 is a reply to message #29849] Mon, 25 March 2002 09:07 Go to previous message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
OK, how about an amalgam of David's and Craigs methods:

FUNCTION WhatDayIsIt, jul_day = jdate, year=year, month=month, day=day,
NUMBER=NUMBER
;+
; Return the day of the week given either the JULDATE
; or
; the date as DAY , MONTH, YEAR
; NUMBER: return the number of days from sunday instead of the string day
name
;-

; convert input to julday
IF N_Elements(jdate) EQ 0 THEN begin
if N_Elements(day) EQ 1 THEN begin
jdate = Julday(month, day, year)
endif else begin
jdate = Systime(/Julian)
endelse
endif

; Julday of any old Sunday
jdate_sunday =2452358L ;= Julday(3,24,2002)

; What day of the week is it? (note the use of round)
dow = ( (round(jdate) - jdate_sunday ) mod 7 )
dow = (dow +7 ) mod 7

if keyword_set(NUMBER) EQ 0 then begin
; return a string day-name
daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', $
'Thursday', 'Friday', 'Saturday']
dow = daysOfWeek[dow]
endif

RETURN, dow

END
IDL> print, WhatDayIsIt(jul = systime(/jul))

Monday

IDL> profiler, /report

Module Type Count Only(s) Avg.(s) Time(s) Avg.(s)

WHATDAYISIT (U) 1 0.000065 0.000065 0.000065 0.000065


--
----------------------------------------
Martin Downing,
Clinical Research Physicist,
Grampian Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.


"trouble" <the_cacc@hotmail.com> wrote in message
news:5f9f0a23.0203210321.25c748ff@posting.google.com...
> David Fanning <david@dfanning.com> wrote in message
news:<MPG.17025cedc0db98d798983c@news.frii.com>...
>>
>> P.S. Sorry for the FOR loop. I was in a hurry. :-(
>>
>
> Tsk, according to my timings that FOR loop is costing us 0.0009 seconds.
> Maybe OK for some, but what if ya gots to know the day *now*? Maybe also
> consider using IntArr(7,/NOZERO)? ;)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: A little handy date function
Next Topic: Re: IDL Movie Viewer

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 14:56:10 PDT 2025

Total time taken to generate the page: 0.00523 seconds