473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ToUniversalTime and Daylight Savings

I am creating an .ics file that when opened (via Outlook) inserts a
meeting into the calendar.

All works fine unless the date and time I'm inserting happens to occur
on the hour the time changes due to daylight savings.

For example in 2004 the hours changed at 2:00 AM on April 4th (the
first Sunday of April). Only on this day, if the start hour is 2 (2:00
AM, 2:15 AM, 2:45 AM), then an extra hour gets added so that 2:00 AM
becomes 3:00 AM, and 2:15 AM becomes 3:15 AM, and so on.

I attempted a terrible hack that checks whether the date and time are
on the first Sunday in April of the year, and the hour is 2, and if
true then I perform a DateTime.AddHours(-1). However I then get an
Outlook error stating 'Cannot import vCalendar file. This time is not
valid due to daylight saving time'

Here is my code. Any suggestions or work arounds? Help appreciated,
thanks.
private void CreateMeeting()
{
string startYear="";
string endYear="";
string startMonth="";
string endMonth="";
string startDay="";
string endDay ="";
string strStartTime="";
string strEndTime="";
string strTimeStamp="";
const string c_strTimeFormat = "yyyyMMdd\\THHmmss\\Z";

//- VCalendar file format: export calendar meeting from outlook and
open in notepad to see file structure
const string VCAL_FILE =
"BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:PUBLISH\n" +
"BEGIN:VEVENT\n\n" +
"DTSTART{0}\n" +
"DTEND{1}\n" +
"LOCATION:{2}\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:te**@teststestetse.ca\n" +
"DTSTAMP:{5}\n" +
"DESCRIPTION:{3}\n" +
"SUMMARY:{4}\n\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:PT15M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"PRIORITY:5\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR" ;
string strSQL = GetSql();
DataSet ds = Common.GetDataSet(strSQL, "Page_Load");
DataRow dr = ds.Tables[0].Rows[0];
string loc = dr["location"].ToString();
string subj = dr["title"].ToString();

DateTime dtmEndDate;
DateTime dtmStartDate = DateTime.Parse(dr["date"].ToString());
DateTime dtmStartTime = DateTime.Parse(dr["starttime"].ToString());
DateTime dtmEndTime = DateTime.Parse(dr["endtime"].ToString());
int intAllDayEvent = int.Parse(dr["alldayevent"].ToString());

//-HACK TO ATTEMPT TO CORRECT 1st DAY APRIL HOURS
if (dtmStartDate.Month == 4 && dtmStartDate.Day < 7 &&
dtmStartDate.DayOfWeek == DayOfWeek.Sunday && dtmStartTime.Hour == 2)
{
dtmStartTime = dtmStartTime.AddHours(-1);
dtmEndTime = dtmEndTime.AddHours(-1);
}

if (intAllDayEvent==1) //-All Day Event (diff format than times)
{
//-Year, Month, Day
dtmEndDate = dtmStartDate.AddDays(1);
startYear = dtmStartDate.Year.ToString(); //4 digits
endYear = dtmEndDate.Year.ToString(); //4 digits
startMonth = AffixZero(dtmStartDate.Month.ToString()); //2 digits
endMonth = AffixZero(dtmEndDate.Month.ToString()); //2 digits
startDay = AffixZero(dtmStartDate.Day.ToString()); //2 digits
endDay = AffixZero(dtmEndDate.Day.ToString()); //2 digits
string strStartDate=string.Format("{0}{1}{2}",startYear,s tartMonth,startDay);
string strEndDate=string.Format("{0}{1}{2}",endYear,endMo nth,endDay);
strStartTime=string.Format(";VALUE=DATE:{0}",strSt artDate);
strEndTime=string.Format(";VALUE=DATE:{0}",strEndD ate);
strTimeStamp=string.Format("{0}T200000Z",strStartD ate);
}

else //-Times (diff format than if 'all day event')
{
dtmEndDate = dtmStartDate;
string strTempStartTime = string.Format("{0} {1}",
dtmStartDate.ToShortDateString(),dtmStartTime.ToLo ngTimeString());
string strTempEndTime = string.Format("{0} {1}",
dtmEndDate.ToShortDateString(),dtmEndTime.ToLongTi meString());
strTimeStamp = (DateTime.Parse(strTempStartTime)).ToUniversalTime ().ToString(c_strTimeFormat);
strStartTime = string.Format(":{0}", strTimeStamp);
strEndTime = string.Format(":{0}",
(DateTime.Parse(strTempEndTime)).ToUniversalTime() .ToString(c_strTimeFormat));
}

//-Event Info
string strEventInfo = "";

//-Details
string strDetails = AddEscapeChars(dr["details"].ToString());
if (strDetails.Length > 0)
{
strEventInfo = string.Format("{0}Details -
{1}{2}",strEventInfo,strDetails,"\\n");
}

//-Weblink
string strWeblink = dr["url"].ToString();
if (strWeblink.Length > 0)
{
strEventInfo = string.Format("{0}Web Link -
{1}{2}",strEventInfo,strWeblink,"\\n");
}
if (strEventInfo.Length > 0)
{
strEventInfo = string.Format("{1}Event
Information{1}-----------------------------{1}{0}",
strEventInfo,"\\n");
}

//-Contact Info
string strContactInfo =
Common.FormatContactInfo(dr["contactname"].ToString(),
dr["contactextension"].ToString(), dr["contactemail"].ToString(), "",
false);
string desc = string.Format("{0}{1}", strEventInfo, strContactInfo);

//-convert string to array of bytes
string vCalendarFile =
String.Format(VCAL_FILE,strStartTime,strEndTime,lo c,desc,subj,strTimeStamp);

System.Text.ASCIIEncoding ascii =new System.Text.ASCIIEncoding();
byte [] vCalbytes= ascii.GetBytes(vCalendarFile);

//-writes 'file' output to stream:
Response.Clear();
Response.ClearHeaders();
Response.ContentType="text/calendar";
Response.AddHeader("content-disposition","inline;
filename=Event.ics"); //sends as .ics file so machine knows to open in
Outlook
Response.BinaryWrite(vCalbytes);
Response.End();
}
Nov 16 '05 #1
1 7813
Ernie,

In the spring, when daylight savings takes affect, an hour is added to the
clock at 2:00 a.m. This means that the clock ticks from 1:59:59 a.m. to
3:00:00 a.m. For timezones that observe daylight savings time, there is no
such thing as 2:00 a.m., 2:15 a.m., or 2:45 a.m. on the day that daylight
savings takes affect (such as April 4, 2004).

"Ernie" <Er**********@uhn.on.ca> wrote in message
news:fa**************************@posting.google.c om...
I am creating an .ics file that when opened (via Outlook) inserts a
meeting into the calendar.

All works fine unless the date and time I'm inserting happens to occur
on the hour the time changes due to daylight savings.

For example in 2004 the hours changed at 2:00 AM on April 4th (the
first Sunday of April). Only on this day, if the start hour is 2 (2:00
AM, 2:15 AM, 2:45 AM), then an extra hour gets added so that 2:00 AM
becomes 3:00 AM, and 2:15 AM becomes 3:15 AM, and so on.

I attempted a terrible hack that checks whether the date and time are
on the first Sunday in April of the year, and the hour is 2, and if
true then I perform a DateTime.AddHours(-1). However I then get an
Outlook error stating 'Cannot import vCalendar file. This time is not
valid due to daylight saving time'

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bathroom_Monkey | last post by:
For posterity's sake, here is an algorithm I created to take a GMT time and convert it to U.S. central time, accounting for daylight saving time. Note: this algorithm can be modified to work for...
2
by: hourang | last post by:
ok im getting tired of looking for an answer and coming up short with scripts that dont work. i have a application that uses GMT for all its times and needs the clients timeoffset for showing the...
10
by: Marc Pelletier | last post by:
Hello, I am writing an application that does some simple astronomical calculations. One of the variables I need is the number of hours passed in this year. I've written the following function ...
3
by: chrisdevey | last post by:
Is there any way to make a System.Timers.Timer adjust for daylight savings time change? In a long running process I set a timer as follows for a daily expiration: _myTimer = new...
3
by: Anna | last post by:
Hi, I've already found out that .Net Framework 1.1 does not properly handle anything that is related to a non-current timezone. Since my project should be released before the release of...
3
by: mmuras | last post by:
I did not see any discussions / threads for this but if there is one please let me know: -First, I am one of only two individuals within my company's IT Dept. -We have a Windows Server 2003 R2...
4
by: Polaris431 | last post by:
I have a web application in ASP.NET that will be used globally. Data is collected on mobile devices running Windows Mobile and sent to the web server where it is stored and can be viewed. Data is...
3
by: Generic Usenet Account | last post by:
Hi, Is there any way to make time-of-day adjustments for daylight savings using only standard time functions? We have a program that executes daily at a fixed time of day. After daylight...
27
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.