Silverfrost Forums

Welcome to our forums

Is CONVDATE@ working ?

3 Oct 2009 6:52 #5113

Gives message 'date out of range'

Where is utility which gives seconds since 1970?

I basically need some date and time routine which returns day of the week

4 Oct 2009 11:05 #5114

Dan,

Try this

       SUBROUTINE SECONDS_SINCE_1970(iseconds) 
       REAL*8 DR 
       call SECONDS_SINCE_1980@(DR)
       iseconds = dr + 315489599
       end

I just wrote a program to call seconds_since_1980@ and added on an increment to the returned seconds until convdate@ gave today's date and that was 31548599 seconds.

Regards

Ian

4 Oct 2009 6:29 (Edited: 5 Oct 2009 3:34) #5115

Thanks for respond from which I've got the idea that convdate@ is somehow working.

[color=olive:4796f1d53e](But holly s@^&t, unbelievable, i've lost several hours to get workaround for this routine and the reason is so dumb: the integer arguments for convdate@ are two byte integers which of course I've not expected! My request to Paul & all at Silverfrost - please remove all integer2 arguments from all your utilities. It is noticeable amount of pain everyone who use them suffered if they use these compilers for 20 years. Nobody expects integer2 for any reason, or cares to save several bytes of memory and hence these utilities are always source of errors, confusions and headache to declare them in each subroutine. Exclusion could be done only to 1-2 utilities which specifically handle bitmaps where for RGB even integer1 are needed but there it is clear why short integers are needed since bitmaps could be hundreds of MB in size)[/color:4796f1d53e]

The convdate@ with that integer*2 arguments and your workaround gives me though some error telling today is Saturday which would be nice but unfortunately it is Sunday already 😦 So please check these additional seconds in 10 years.

I've made such workaround to get day of the week

  real*8 dsecs1980
  call SECONDS_SINCE_1980@(dsecs1980) 
  Weeks=(dsecs1980+86400*2)/(86400*7)
  idayOfWeek = (Weeks-int(Weeks))*7.

idayOfWeek : 0 -Sunday, 1 -Monday ...6 - Saturday

4 Oct 2009 8:54 #5116

Dan,

Sorry, I might have got that a little wrong. My new estimate is 315532800.

There may also be a difference due to your time difference, so you could try moving to London and trying it again. Or run the following badly written code:

winapp
CHARACTER*30 DATE, TIME, ZONE
INTEGER*4  VALUES(8),idate,itoday,itoday_seconds
INTEGER*2 IDW,IDAY,IMONTH,IYEAR
real*8 dr
!find today's date
call DATE_AND_TIME(DATE, TIME, ZONE, VALUES)
!calculate today's date as an integer of the form yyyymmdd
itoday = (values(1)*100+values(2))*100+values(3)
Print *,'Today''s date             ',itoday
print *,'UTC time difference      ',values(4),' minute',values(4)*60,'second'
call SECONDS_SINCE_1980@(DR) 
itoday_seconds = (VALUES(5)*60+VALUES(6))*60+VALUES(7)
!find the start of today
Print *,'Seconds passed today     ',itoday_seconds
iseconds            = dr - itoday_seconds
iadditional_seconds = 0
increment           = 3600
10 continue
idate_test = 0
do while(idate_test .ne. itoday)
  iadditional_seconds = iadditional_seconds + increment
  nseconds = iseconds + iadditional_seconds
  call convdate@(nseconds,IDW,IDAY,IMONTH,IYEAR)
  idate_test = (iyear*100+imonth)*100+iday
enddo
if(increment .eq. 3600)then
!just jumped and hour into the target day so jump back and increment in seconds
  iadditional_seconds = iadditional_seconds - increment
  increment = 1
  goto 10
endif
print *,'Additional seconds       ',iadditional_seconds
print *,'Seconds to start of today',nseconds,' from 1970'
Print *,'Today''s test date        ',idate_test

end

Actually, what was wrong was that I forgot to subtract the number of seconds that had passed today in this test program. That meant that it thought that today started at about 12:00. Please try it and see if you get the same result.

Ian

4 Oct 2009 9:46 #5118

Yep, library code agrees 😃

      SUBROUTINE SECONDS_SINCE_1970@(DR)
      REAL*8 DR
      call SECONDS_SINCE_1980@(DR)
      dr=dr+315532800d0
      end
5 Oct 2009 2:10 #5120

Yes, that works fine on opposite side of the earth

Please login to reply.