Important alert: (current site time 7/15/2013 10:12:45 PM EDT)
 

VB icon

ASP - EST or EDT

Email
Submitted on: 4/1/2005 10:16:50 PM
By: Brian Battles WS1O  
Level: Intermediate
User Rating: Unrated
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 8173
author picture
(About the author)
 
     IMPROVED Apr 2, 2005: This is a hunk of code to remind a visitor to change their clock from EST to EDT (Standard Time to Daylight Time...I'm in CT USA, so we use Eastern Time...bear with me!) Also, if you don't want to paste this or retype it, you can download a ZIP file of this ASP code at http://www.w1edh.org/est2edt.zip
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: ASP - EST or EDT
' Description:IMPROVED Apr 2, 2005: This is a hunk of code to remind a visitor to change their clock from EST to EDT (Standard Time to Daylight Time...I'm in CT USA, so we use Eastern Time...bear with me!) Also, if you don't want to paste this or retype it, you can download a ZIP file of this ASP code at http://www.w1edh.org/est2edt.zip
' By: Brian Battles WS1O
'
' Assumes:Somehow I'm not sure this is very efficient...or free of bugs! Can anyone think of a better way to do this? Please leave some kind of feedback! Thanks....
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9154&lngWId=4'for details.'**************************************

<%
' Written By: Brian Battles WS1O, Rocky Hill, CT USA
'Date: April 2, 2005
' E-Mail: BrianB@BattlesZone.com
'Web site: http://www.BrianBattles.com/
'
' if you find any bugs, please let me know...
' if you can think of any improvements or ways to this more efficiently, please let me know!
Dim EDT
Dim EST
Dim EDTorEST
Dim dDate' using a variable instead of the Date() function because then we can test using other dates, eg, dDate = "4/4/2005"
' this is just easier than typing this stuff over and over!
Const EDT_NAME = "<B>DAYLIGHT SAVING TIME</B>"
Const EST_NAME = "<B>STANDARD TIME</B>"
Const AT2AM = "AT 2 AM SUNDAY"
Const FORWARD = "TURN YOUR CLOCKS FORWARD 1 HOUR"
Const BACK = "TURN YOUR CLOCKS BACK 1 HOUR"
Const TMNITE = "BEFORE YOU GO TO BED TOMORROW NIGHT"
Const TSNITE = " BEFORE YOU GO TO BED THIS SATURDAY NIGHT"
Const TNITE = " BEFORE YOU GO TO BED TONIGHT!"
Sub GetThisYearsDates()
' got these dates from an almanac; I don't know any algorithm to calculate them on the fly
Select Case Year(dDate)
Case 2005
EDT = "4/3/" & Year(Date)
EST = "10/30/" & Year(Date)
Case 2006
EDT = "4/2/" & Year(Date)
EST = "10/29/" & Year(Date)
Case 2007
EDT = "4/1/" & Year(Date)
EST = "10/28/" & Year(Date)
Case 2008
EDT = "4/6/" & Year(Date)
EST = "10/26/" & Year(Date)
Case 2009
EDT = "4/5/" & Year(Date)
EST = "10/25/" & Year(Date)
Case Else
' who the hell knows?
End Select
End Sub
Function AreWeInEdtOrEst()
If DateValue(dDate) < DateValue(EDT) Then
' we're below EDT, so it's EST
EDTorEST = "EST"
ElseIf DateValue(dDate) > DateValue(EST) Then
' we're above EST so it's EST
EDTorEST = "EST"
ElseIf DateValue(dDate) < DateValue(EST) Then
' we're below EST, so it's EDT
EDTorEST = "EDT"
ElseIf DateValue(dDate) > DateValue(EDT) Then
' we're above EDT so it's EDT
EDTorEST = "EDT"
ElseIf DateValue(dDate) = DateValue(EDT) Then
' EDT starts today
If TimeValue(Time) > TimeValue("2:00 AM") Then
EDTorEST = "EDT"
Else
EDTorEST = "EST"
End If
ElseIf DateValue(dDate) = DateValue(EST) Then
' EST starts today
If TimeValue(Time) > TimeValue("2:00 AM") Then
EDTorEST = "EST"
Else
EDTorEST = "EDT"
End If
Else
' huh?
End If
End Function
Function CreateMessage()
GetThisYearsDates
AreWeInEdtOrEst
' **********************************
' for testing...
' Createmessage = "We're in " & EDTorEST & "<BR>"
' **********************************
Dim TodayVal
Dim EDT_0
Dim EDT_1
Dim EDT_2
Dim EDT_3
Dim EDT_6
Dim EST_0
Dim EST_1
Dim EST_2
Dim EST_3
Dim EST_6
EDT_0 = DateValue(EDT)
EDT_1 = DateValue(EDT) - 1
EDT_2 = DateValue(EDT) - 2
EDT_3 = DateValue(EDT) - 3
EDT_6 = DateValue(EDT) - 6
EST_0 = DateValue(EST)
EST_1 = DateValue(EST) - 1
EST_2 = DateValue(EST) - 2
EST_3 = DateValue(EST) - 3
EST_6 = DateValue(EST) - 6
TodayVal = DateValue(dDate)
If EDTorEST = "EDT" Then
' prepare for EST
If TodayVal < EST_2 Then
CreateMessage = BACK & TMNITE & ", " & EST & "!<BR>" & EST_NAME & " BEGINS " & AT2AM & " (" & EDT_NAME & " TIME IS OVER)"
ElseIf TodayVal >= EST_3 And TodayVal <= EST_6 Then
CreateMessage = BACK & TSNITE & ", " & EST & "!<BR>" & EST_NAME & " BEGINS " & AT2AM & " (" & EDT_NAME & " TIME IS OVER)"
Else
Select Case TodayVal
Case EST_1
CreateMessage = BACK & TNITE & "<BR>" & EST_NAME & " BEGINS " & AT2AM & " (" & EDT_NAME & " TIME IS OVER)"
Case EST_2
CreateMessage = BACK & TMNITE & ", " & EST & "!<BR>" & EST_NAME & " BEGINS " & AT2AM & " (" & EDT_NAME & " TIME IS OVER)"
Case EST_0
If TimeValue(Time) < TimeValue("2:00 AM") Then
CreateMessage = BACK & " AT 2:00 AM THIS MORNING!<BR>" & EST_NAME & " " & AT2AM & " SUNDAY (" & strEDSTTime & " IS OVER)"
Else
CreateMessage = "DID YOU " & BACK & " BEFORE YOU WENT TO BED LAST NIGHT?<BR>" & EST_NAME & " HAS BEGUN (" & EDT_NAME & " IS OVER)"
End If
End Select
End If
Else
' prepare for EDT
If TodayVal < EDT_2 Then
CreateMessage = FORWARD & TMNITE & ", " & EDT & "!<BR>" & EDT_NAME & " BEGINS " & AT2AM & " (" & EST_NAME & " IS OVER)"
ElseIf TodayVal >= EDT_3 And TodayVal <= EDT_6 Then
CreateMessage = FORWARD & TSNITE & ", " & EDT & "!<BR>" & EDT_NAME & " BEGINS " & AT2AM & " (" & EST_NAME & " IS OVER)"
Else
Select Case TodayVal
Case EDT_1
CreateMessage = FORWARD & TNITE & "<BR>" & EDT_NAME & " BEGINS " & AT2AM & " (" & EST_NAME & " IS OVER)"
Case EDT_2
CreateMessage = FORWARD & TMNITE & ", " & EDT & "!<BR>" & EDT_NAME & " BEGINS " & AT2AM & " (" & EST_NAME & " IS OVER)"
Case EDT_0
If TimeValue(Time) < TimeValue("2:00 AM") Then
CreateMessage = FORWARD & " AT 2:00 AM THIS MORNING!<BR>" & EDT_NAME & " BEGINS " & AT2AM & " (" & EST_NAME & " IS OVER)"
Else
CreateMessage = "DID YOU " & FORWARD & " BEFORE YOU WENT TO BED LAST NIGHT?<BR>" & EDT_NAME & " HAS BEGUN (" & EST_NAME & " IS OVER)"
End If
End Select
End If
End If
End Function
' *******************************************************************************************
' here's our main routine that calls the others
dDate = Date' I used a variable so I could change it for testing, eg, dDate = DateValue("4/4/2005")
' this is the line we use for the actual ASP
Response.Write "<CENTER><FONT SIZE='4' COLOR='#FF00FF'>" & CreateMessage & "<FONT><BR>"
' *******************************************************************************************
%>


Other 9 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.