Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 820
  • Last Modified:

universal Time and asp.net

Currently have an application that manages time-off requests and is automated to provide a calendar vcs file that will be attached to an email and merged into their Outlook Calendar.  However the time is off from what is actually the correct time.  I am not sure of how to solve this problem.  

If the time off request is from 8 AM - 5 PM, it will display that on the HTML side of things but when creating the calendar file, it will be an hour off.  The calendar response will read 9 AM - 6 PM.   I can't seem to figure out how to get it to not be an hour off.   I use the universalTime as that appears to be the only way to get the fields formatted correctly.

Suggestions.
This is the Calendar Event.  
    Public Property StartDate() As DateTime
        Get
            Return _StartDate
        End Get
        Set(ByVal value As DateTime)
            _StartDate = value
        End Set
    End Property
 
    Public Property EndDate() As DateTime
        Get
            Return _EndDate
        End Get
        Set(ByVal value As DateTime)
            _EndDate = value
        End Set
    End Property
 
    Public Function BuildVCalendar() As String
        Dim sw As New System.IO.StringWriter
        sw.WriteLine("BEGIN: VCALENDAR")
        sw.WriteLine("VERSION:1.0")
        sw.WriteLine("BEGIN: VEVENT")
        'EXAMPLE: sw.WriteLine("DTSTART:20050314T160000Z ")
        sw.WriteLine("DTSTART:{0:yyyyMMdd\THHmmss\Z}", _
           StartDate.ToUniversalTime)
        sw.WriteLine("DTEND:{0:yyyyMMdd\THHmmss\Z}", _
           EndDate.ToUniversalTime)
        'sw.WriteLine("TRANSP:1") 'Free Time?
        sw.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{0}", _
           Description)
        sw.WriteLine("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", Summary)
        sw.WriteLine("PRIORITY:{0}", Priority)
        sw.WriteLine("END:VEVENT")
        sw.WriteLine("END:VCALENDAR")
        Return sw.ToString()
 
    End Function

Open in new window

0
kkluth
Asked:
kkluth
  • 4
  • 3
1 Solution
 
njackson60Commented:
You mentioned HTML - I'm assuming this is a web application as the VB code you posted doesn't show whether or not it is an ASP.NET web app.  You also mentioned that it is automated - is that done in real-time while the user is working in the web app or through a secondary process (like a scheduled task)?
If you can provide more details, that would lead to a clearer understanding of the issue.
0
 
kkluthAuthor Commented:
Yes this is a web application written in asp.net. The process goes like this and it is all real time. A employee requests time off the data is stored in the database. An email is fired off to their supervisor asking them to approve the time off. Throughout the whole web application the time that is displayed is correct. Once the supervisor approves the time off an email is generated with the above code being launched creating an vcs attachment. It is in the creation of the vcs file that the time is off by an hour.

In the email that is finally sent to supervisor and employee displays the following text in the email.  Also I am attaching the vcs file, so you can see that the time is off.

Start Date/Time              End Date/Time
10/31/2008 8:00:00 AM 10/31/2008 5:00:00 PM


myData.txt
CalendarRequest.bmp
0
 
njackson60Commented:
The hour off is a dead giveaway that this is a daylight savings time issue.  The VCS file you sent shows a GMT start time of 1300 and a GMT end time of 2200 - 9:00 AM to 6:00 PM just as you're seeing it.
Without knowing the exact process that generates the VCS file, you might want to check out the DateTimeOffset structure:
http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx
You might also want to check out the System.TimeZoneInfo object as well:
http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx
HTH
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
kkluthAuthor Commented:
I am attaching code that will show you a bit more of the process of which things get generated.  I also tried implementing the DateTimeOffset and received the following error.
_btnApprove_click:The UTC Offset for Utc DateTime instances must be 0. Parameter name: offset  
 Not sure of how to implement DateTimeOffset
Dim MyStartTime = New DateTimeOffset(StartDate.ToUniversalTime, New TimeSpan(-5, 0, 0))
Dim MyEndTime = New DateTimeOffset(EndDate.ToUniversalTime, New TimeSpan(-5, 0, 0))
sw.WriteLine("DTSTART:{0:yyyyMMdd\THHmmss\Z}", _
MyStartTime)
sw.WriteLine("DTEND:{0:yyyyMMdd\THHmmss\Z}", _
MyEndTime)
This is the only area of code that I try and format the date to this is right here.   Is there some way in the VCALENDAR request to specify the timezone?

Calendar.aspx page
    Dim StartDate, EndDate As DateTime 'Variable Declaration
Function Main()
...
                    StartDate = reader("StartDate")
                    EndDate = reader("EndTime")
...
End Function
 
Sub _btnApprove_Click
...
Dim sString As String
 
                Dim icalendar As New OutlookCalendar
                icalendar.StartDate = StartDate
                icalendar.EndDate = EndDate
                sString = icalendar.BuildVCalendar() 'variable that has it contents written to a memorystream and is attached to an email.
...
End Sub
 
Calendar Event VB Class file.  
    Public Property StartDate() As DateTime
        Get
            Return _StartDate
        End Get
        Set(ByVal value As DateTime)
            _StartDate = value
        End Set
    End Property
 
    Public Property EndDate() As DateTime
        Get
            Return _EndDate
        End Get
        Set(ByVal value As DateTime)
            _EndDate = value
        End Set
    End Property
 
    Public Function BuildVCalendar() As String
        Dim sw As New System.IO.StringWriter
        sw.WriteLine("BEGIN: VCALENDAR")
        sw.WriteLine("VERSION:1.0")
        sw.WriteLine("BEGIN: VEVENT")
        'EXAMPLE: sw.WriteLine("DTSTART:20050314T160000Z ")
        sw.WriteLine("DTSTART:{0:yyyyMMdd\THHmmss\Z}", _
           StartDate.ToUniversalTime)
        sw.WriteLine("DTEND:{0:yyyyMMdd\THHmmss\Z}", _
           EndDate.ToUniversalTime)
        'sw.WriteLine("TRANSP:1") 'Free Time?
        sw.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{0}", _
           Description)
        sw.WriteLine("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", Summary)
        sw.WriteLine("PRIORITY:{0}", Priority)
        sw.WriteLine("END:VEVENT")
        sw.WriteLine("END:VCALENDAR")
        Return sw.ToString()
 
    End Function

Open in new window

0
 
njackson60Commented:
VCS files use UTC - so if someone were to generate a request to you, say in Japan and send it to you, you could import that into Outlook and have it come up as local time.
It's your timespan - try this code (notice the use of the timespan and DateTimeOffset in the BuildVCalendar() function):
 

Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Me.Show()
        Dim StartDate As DateTime = "11/4/2008 8:00 AM"
        Dim EndDate As DateTime = "11/4/2008 5:00 PM"
        Dim MyStartTime = New DateTimeOffset(StartDate.ToUniversalTime, DateTimeOffset.Now - DateTimeOffset.UtcNow)
        Dim MyEndTime = New DateTimeOffset(EndDate.ToUniversalTime, DateTimeOffset.Now - DateTimeOffset.UtcNow)
 
        Dim icalendar As New OutlookCalendar
        icalendar.StartDate = StartDate
        icalendar.EndDate = EndDate
        Dim sString As String = icalendar.BuildVCalendar(StartDate, EndDate, "Meeting Description", "Summary", 0)
 
    End Sub
 
End Class
 
Public Class OutlookCalendar
    Dim _StartDate As DateTime
    Dim _EndDate As DateTime
 
    Public Property StartDate() As DateTime
        Get
            Return _StartDate
        End Get
        Set(ByVal value As DateTime)
            _StartDate = value
        End Set
    End Property
 
    Public Property EndDate() As DateTime
        Get
            Return _EndDate
        End Get
        Set(ByVal value As DateTime)
            _EndDate = value
        End Set
    End Property
 
    Public Function BuildVCalendar(ByVal startDate As DateTime, _
 ByVal endDate As DateTime, ByVal description As String, _
 ByVal summary As String, ByVal priority As Integer) As String
        Dim sw As New System.IO.StringWriter
        sw.WriteLine("BEGIN: VCALENDAR")
        sw.WriteLine("VERSION:1.0")
        sw.WriteLine("BEGIN: VEVENT")
        'EXAMPLE: sw.WriteLine("DTSTART:20050314T160000Z ")
        sw.WriteLine("DTSTART:{0:yyyyMMdd\THHmmss\Z}", _
                     New DateTimeOffset(startDate.ToUniversalTime, DateTimeOffset.Now - DateTimeOffset.UtcNow))
        'startDate.ToUniversalTime)
        sw.WriteLine("DTEND:{0:yyyyMMdd\THHmmss\Z}", _
                     New DateTimeOffset(endDate.ToUniversalTime, DateTimeOffset.Now - DateTimeOffset.UtcNow))
        'endDate.ToUniversalTime)
        'sw.WriteLine("TRANSP:1") 'Free Time?
        sw.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{0}", _
           description)
        sw.WriteLine("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", summary)
        sw.WriteLine("PRIORITY:{0}", priority)
        sw.WriteLine("END:VEVENT")
        sw.WriteLine("END:VCALENDAR")
        Return sw.ToString()
 
    End Function
 
End Class

Open in new window

0
 
kkluthAuthor Commented:
Thank's that worked just great.
0
 
kkluthAuthor Commented:
Your help was/is greatly appreciated.  Thank you for providing the code example to get this task of mine completed.  
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now