You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
OK I think I have it, and even see a pattern here but can't put my finger on it...
Since I only need to know In APRIL, I can easy do the math...
Since It's a SYSTEMTIME structure I set a SYSTEMTIME structure up like this to test:
It seems to return the date correctly....
Code:
Local tt As systemtime
tt = st
tt.wday = %Monday
tt.wyear = 2001
tt.wMonth = 4
MsgBox Str$(CountDownToDST(tt))
MsgBox STtoNISTTime(0,g_ClientPingTime)
Exit Function
Function CountDownToDST(st As SYSTEMTIME)Export As Long
If st.wMonth <> %April Or st.wday > 8 Then Exit Function 'Past the DST marker already, 1st Sunday of April
Select Case st.wday
Case %Sunday
Function = 0
Case %Monday
Function = 6
Case %Tuesday
Function = 5
Case %Wednesday
Function = 4
Case %Thursday
Function = 3
Case %Friday
Function = 2
Case %Saturday
Function = 1
End Select
End Function
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
See also: daylight saving source for PBDOS (Source Code Forum) and the connected discussion in the PBDOS Forum
------------------
Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu) http://zijlema.basicguru.eu *** Opinions expressed here are not necessarily untrue ***
Just remember that this routine would not be accurate for ALL years, only from 1999 (or was it 1998) forward. (Unless of course they change the rules again....it use to begin the LAST Sunday in April).
Ray
Just pointing this out in case your looking to dertermine the start for years within the past. (If that's the case, we had one year in which we had daylight savings time for an entire year...during the 70's fuel shortage, as I recall).
------------------
[This message has been edited by Ray Corry (edited April 10, 2000).]
That's exactly right, that link above describes it all, but the good point is that it's in a DLL, and can be quickly modified and distributed in the event we DO change the time again....
Personally, the FIRST sunday is easier to figure out than the LAST sunday (I think)..
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
I think you are wrong. Finding the last Sunday of any month is the same easy as finding the first.
See the source code Forum to download a Daylight Saving routine for PBDLL60
------------------
Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu) http://zijlema.basicguru.eu *** Opinions expressed here are not necessarily untrue ***
Maybe easy for you! *Grin*, you make that stuff look easy!!
I don't understand the julian date stuff very well except to say I count 1 to 365 and I have a julian date somewhere in there (I used to work for the government and had to use it, but never understood how it was derived programmatically)...
Question for you, since I am very impressed with the functions.
What will the functions return?
ie:
FirstSundayOfApril
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
See my website (www.basicguru.com/zijlema/). Surf to the Javascript page to read an explanation on Julian Day Numbers.
To answer your question here and now: each of my functions Last/FirstSundayOfMonth(year) returns the appropriate date for the given year in the form of a long integer (Julian). This Julian is the number of days elapsed since November 25, 4714 BC.
Using (long) integers for a calendar date makes counting / counting down very easy. Once the routine has found the Julian for the last/first Sunday, the JulToDate(Jul) function converts the JDN back to a valid date.
Derived from the Julian, the days of the week are the remainders of a repetetive division by 7 (the MOD operator), where: Monday = 0 thru Sunday = 6. Sometimes I add 1 to these values in order to get Monday thru Sunday = 1 - 7, but in this routine this is not really important. We just want to stop the function on the appropriate day.
------------------
[This message has been edited by Egbert Zijlema (edited April 12, 2000).]
Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu) http://zijlema.basicguru.eu *** Opinions expressed here are not necessarily untrue ***
While the math is still confusing to me, I will learn it
Also, I wrote these, since if may be either October or April when the app is run, and if it is, I will need to do a countdown TO the first sunday or LAST SUNDAY so I wrote these fine little functions, and it works great!
'=============================================================================
Function DateofFirstSundayOfApril(wYear As Integer) Export As Long 'It will be a systemtime.wday long integer
Function = Val(Right$(Parse$(JulToDate(FirstSundayOfApril(wYear)),2),2))
End Function
'=============================================================================
Function DateOfLastSundayOfOctober(wYear As Integer)Export As Long
Function = Val(Right$(Parse$(JulToDate(LastSundayOfOctober(wYear)),2),2))
End Function
'=============================================================================
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
By the way, for anyone reading this.
You too can take advantage of a bug in Windows 3.1 THROUGH Windows 2000!!!!!!!!!!
I want to say, pull my date up to October 15th and determine how many days it is until Oct 31'st, BUT I don't want to mess up my system time because of other applications...
Double Click the clock, CHANGE it, but do NOT apply/cancel/ok out of it. Leave running in background, the system time will now show OCTOBER, but you can click cancel and it will go BACK to current date/time after you run your application....
I don't know if it is a debug, a bug, or just a cool feature, but I love it...
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
But doing that does affect other applications! For example, if I run a DOS app that constantly displays the date/time on my NT4 machine, and I use the clock applet to change the date but I do not click Ok, the DOS app shows the date-changes as I make them.
Yes it will show the changes, which is why it is a BUG not a feature, if a time sensitive application changes time, it could be detramental.
When I was creating the client piece to Nucelar Time Server it would continuously change and detonate, ICQ will detonate, several othher apps GPF'd also, so do be careful...
BUT what a great troubleshooting tool when needed!!!!!!!!
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
One more quick question before my new fridge gets here and I have to go put it in...
The NIST accounts for what is called a "Leap Second", not to be confused with LEAP YEAR. It is used to adjust for inaccuracies in the earths rotation etc....
Does anyone know HOW this is determined when it will be used?
It is always 1 second at teh end of the month that gets added if it is used.
Basically that's the last piece of the puzzle and my SYSTEMTIME_TO_NISTTime will be complete
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
In the European Union the Daylight Saving Period began on the last Sunday of March. One week later the US should follow, but since the change of the clock in Europe there seems to be a permanent 10 hours' difference when comparing local time in The Netherlands by the time of this server.
Since the first Sunday of April the 'normal' difference of 9 hours should be restored. How come? Did California not adjust its clocks? In other words: does it differ from state to state in America? And if so, can someone from the US tell me on which day the clock goes one hour ahead in which state?
------------------
Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu) http://zijlema.basicguru.eu *** Opinions expressed here are not necessarily untrue ***
And if so, can someone from the US tell me on which day the clock goes one hour ahead in which state?
Not all states participate in daylight savings time, but generally speaking on Sunday morning at 2am we switch our clocks over, does that help?
Another note, something I found in our database when working with some of our technicians down in Australia, the date came up one day ahead of time, could it be an international dateline issue??
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
Before the switch in Europe 'my' clock was 9 hours ahead, compared to Power Basic's in Carmel (CA). Last Sunday of March the difference became 10 hours, due to the European adjustment. But after a week it should be back to 9 again (DST in America), which did not happen.
Maybe Power Basic did not adjust their server's clock?
------------------
Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu) http://zijlema.basicguru.eu *** Opinions expressed here are not necessarily untrue ***
This is untested, but I'm sure it will work. It is very similar to my "Thanksgiving Day" function.
Code:
Dim WHATDATE$
Call DATEFormat (DayLightDate(2000), WHATDATE$)
txtDayLightSavingsTime.Text = WHATDATE$
Function DayLightDate (iYear) Export As Long
DayLightDate = SetMonday(DateSerial(iYear, 3, 31)) + 6
End Function
Function SetMonday (ByVal dDateSerial As Double) _
Export As Long
Dim lDateSerial As Long, iSetMonday As Integer
lDateSerial = Fix(dDateSerial)
iSetMonday = (lDateSerial - 2) Mod 7
Function = lDateSerial - iSetMonday
End Function
FUNCTION DATESERIAL(ByVal iInYears AS INTEGER, _
ByVal iInMonths AS INTEGER, ByVal iInDays _
AS INTEGER ) EXPORT AS DOUBLE
Dim dBuildDate As Double
Dim iYears As Integer
Dim iMonths As Integer
Dim iDays As Integer
iYears = iInYears
iMonths = iInMonths
iDays = iInDays - 1
If iYears > 1000 Then iYears = iYears - 1900
dBuildDate = Int(iYears * 365.248) + 2
iYears = iYears + 1900
Do
IF iMonths = %JAN THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in January
IF iMonths = %FEB THEN EXIT DO
If iYears Mod 4 Then
dBuildDate = dBuildDate + 28 'Days in February
Else
dBuildDate = dBuildDate + 29 'Days in Leap February
End If
IF iMonths = %MAR THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in March
IF iMonths = %APR THEN EXIT DO
dBuildDate = dBuildDate + 30 'Days in April
IF iMonths = %MAY THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in May
IF iMonths = %JUN THEN EXIT DO
dBuildDate = dBuildDate + 30 'Days in June
IF iMonths = %JUL THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in July
IF iMonths = %AUG THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in August
IF iMonths = %SEP THEN EXIT DO
dBuildDate = dBuildDate + 30 'Days in September
IF iMonths = %OCT THEN EXIT DO
dBuildDate = dBuildDate + 31 'Days in October
IF iMonths = %NOV THEN EXIT DO
dBuildDate = dBuildDate + 30 'Days in November
IF iMonths = %DEC THEN EXIT DO
DATESERIAL = 0
Exit Function
Loop
dBuildDate = dBuildDate + iDays
FUNCTION = dBuildDate
End Function
FUNCTION TIMESERIAL(ByVal iHours AS INTEGER, _
ByVal iMins AS INTEGER, ByVal iSecs AS INTEGER ) _
EXPORT AS DOUBLE
Dim iHoursPerDay As Integer
Dim iMinsPerDay As Integer
Dim lSecsPerDay As Long
'A time serial number is a fraction of a day
iHoursPerDay = 24
iMinsPerDay = 60 * iHoursPerDay
lSecsPerDay = 60 * iMinsPerDay
FUNCTION = ( iHours / iHoursPerDay ) + _
( iMins / iMinsPerDay ) + ( iSecs / lSecsPerDay )
End Function
SUB DATEFormat (ByVal dDateSerial AS DOUBLE, _
WHATDATE AS STRING * 10) EXPORT
Dim iYears As Integer, iMonths As Integer, _
iDays As Integer, sDate As String
iYears = Int(dDateSerial - 2 / 365.248)
iDays = (Int(dDateSerial) - Int(iYears * 365.248)) - 1
iYears = iYears + 1900
Do
INCR iMonths
If iDays < 32 Then Exit Do
Select Case iMonths
CASE %FEB
If iYears Mod 4 Then
iDays = iDays - 28
Else
iDays = iDays - 29
End If
CASE %APR
iDays = iDays - 30
CASE %JUN
iDays = iDays - 30
CASE %SEP
iDays = iDays - 30
CASE %NOV
iDays = iDays - 30
Case Else
iDays = iDays - 31
End Select
Loop
If iMonths < 10 Then
sDate = "0" + LTrim$(Str$(iMonths)) + "-"
Else
sDate = LTrim$(Str$(iMonths)) + "-"
End If
If iDays < 10 Then
sDate = sDate + "0" + LTrim$(Str$(iDays)) + "-" + _
LTrim$(Str$(iYears))
Else
sDate = sDate + LTrim$(Str$(iDays)) + "-" + _
LTrim$(Str$(iYears))
End If
WHATDATE = sDate
End Sub
SUB TIMEFormat (ByVal dDateSerial AS DOUBLE, _
WHATTIME AS STRING * 8) EXPORT
Dim lDate As Long
Dim iHours As Integer, iMinutes As Integer, _
iSeconds As Integer, sTime As String
Dim iHoursPerDay As Integer
Dim iMinsPerDay As Integer
Dim lSecsPerDay As Long
Dim sAM As String * 3
'A time serial number is a fraction of a day
sAM = " AM"
iHoursPerDay = 24
iMinsPerDay = 60 * iHoursPerDay
lSecsPerDay = 60 * iMinsPerDay
lDate = Int(dDateSerial)
dDateSerial = dDateSerial - lDate
'Now dDateSerial contains only the time as a fraction of a day
iHours = Int(dDateSerial * iHoursPerDay)
If iHours Then dDateSerial = dDateSerial - _
(iHours / iHoursPerDay)
iMinutes = Int(dDateSerial * iMinsPerDay)
If iMinutes Then dDateSerial = dDateSerial - _
(iMinutes / iMinsPerDay)
iSeconds = Int(dDateSerial * lSecsPerDay)
If iHours < 10 Then
sTime = "0" + LTrim$(Str$(iHours)) + ":"
If sTime = "00:" Then sTime = "12:"
ElseIf iHours > 12 Then
iHours = iHours - 12
If iHours < 10 Then
sTime = "0" + LTrim$(Str$(iHours)) + ":"
Else
sTime = LTrim$(Str$(iHours - 12)) + ":"
End If
sAM = " PM"
ElseIf iHours = 12 And iMinutes > 0 Then
sTime = "12:"
sAM = " PM"
Else
sTime = LTrim$(Str$(iHours)) + ":"
End If
If iMinutes < 10 Then
sTime = sTime + "0" + LTrim$(Str$(iMinutes)) + ":"
Else
sTime = sTime + LTrim$(Str$(iMinutes)) + ":"
End If
If iSeconds < 10 Then
sTime = sTime + "0" + LTrim$(Str$(iSeconds))
Else
sTime = sTime + LTrim$(Str$(iSeconds))
End If
WHATTIME = sTime + sAM
End Sub
[This message has been edited by David Lloyd (edited May 04, 2000).]
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment