Search code examples
vb.netgoogle-calendar-api

Compiler warning for Google Calendar Event Start / End Properties


I am using Google Calendar v3 API and I have a Visual Basic application.

It has worked for years and still does but I noticed a warning during compilation concerning:

Googles.Apis.Calendar.v3.Data.Event

I init the variable:

Dim oEvent As New Data.Event With {
    .Summary = sEvent.strTitle,
    .Description = sEvent.strEventDetails,
    .Location = sEvent.strLocation
}

But one bit in particular:

Dim eventStartDT As New Data.EventDateTime() With {
        .DateTime = dtDateTimeStart
}

Dim eventEndDT As New Data.EventDateTime() With {
    .DateTime = dtDateTimeFinish
}

oEvent.Start = eventStartDT
oEvent.End = eventEndDT

I have looked at the docs:

https://developers.google.com/calendar/api/v3/reference/events

They imply my code it OK. It states:

  "start": {
    "date": date,
    "dateTime": datetime,
    "timeZone": string
  },
  "end": {
    "date": date,
    "dateTime": datetime,
    "timeZone": string
  },

Yet, during compile:

... Program.vb(955,26): warning BC40000: 'Public Overridable Overloads Property DateTime As Date?' is obsolete: 'This property is obsolete and may behave unexpectedly; please use DateTimeDateTimeOffset instead.'.

I am not sure what to do.

enter image description here

I confirm that the new property is listed:

enter image description here


Solution

  • It appears that this section:

    Dim eventStartDT As New Data.EventDateTime() With {
            .DateTime = dtDateTimeStart
    }
    
    Dim eventEndDT As New Data.EventDateTime() With {
        .DateTime = dtDateTimeFinish
    }
    
    oEvent.Start = eventStartDT
    oEvent.End = eventEndDT
    

    should be this:

    Dim eventStartDT As New Data.EventDateTime() With {
            .DateTimeDateTimeOffset = New DateTimeOffset(dtDateTimeStart)
    }
    
    Dim eventEndDT As New Data.EventDateTime() With {
        .DateTimeDateTimeOffset = New DateTimeOffset(dtDateTimeFinish)
    }
    
    oEvent.Start = eventStartDT
    oEvent.End = eventEndDT
    

    There is also a constructor that allows you to set the offset from UTC. See the relevant documentation here.