SkyeBoniwell
SkyeBoniwell

Reputation: 7092

pass date to JSON feed

I am using the fullCalendar in a vb.net setting. I use a JSON feed contained within an aspx page to pass data to the calendar like this:

events: "JSONcalendarFeed.aspx"

I was wondering if there's a way to pass the currently selected month in fullCalendar to the page that generates the JSON feed so I can pull data for that month. Also whenever a year changed in the calendar, I'd need to pass in that new year.

Thanks!

Upvotes: 2

Views: 1328

Answers (2)

Piotr Kula
Piotr Kula

Reputation: 9821

PAGE

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="diaryFeed.aspx.vb" Inherits="ClubSites.diaryFeed" %>
<%  Response.Write(respondBack)%>

CODE BEHIND

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Request.QueryString.ToString <> "" Then
            'I don't understand why fullCalendar uses a Unix timestamp.. but use these queries if you use UNIX timestamp, common in PHP apparently

            If IsNothing(Request.QueryString("start")) Then
                _startDate = Date.Now.AddYears(-1)
                _endDate = Date.Now.AddYears(1)
            Else
                _startDate = CDateFromUNIX(Request.QueryString("start"))
                _endDate = CDateFromUNIX(Request.QueryString("end"))

            End If
            Try
                If Not Request.QueryString("Timestart").Length = 0 And Not Request.QueryString("TimeEnd").Length = 0 Then
                    _startDate = CDate(Request.QueryString("Timestart"))
                    _endDate = CDate(Request.QueryString("TimeEnd"))
                End If
            Catch ex As Exception

            End Try
            'End If

 respondBack = JsonConvert.SerializeObject([mycustom function that generates a data table], New Newtonsoft.Json.Converters.IsoDateTimeConverter())


end sub

I use json .net to convert my outgoing data to json so that diary can understand it

and a helper function to convert the Unix timestamps to .NET one

 Function CDateFromUNIX(ByVal timestamp As Double) As DateTime
        Dim origin As DateTime = New DateTime(1970, 1, 1, 0, 0, 0, 0)
        Return origin.AddSeconds(timestamp)
    End Function

Upvotes: 1

Magnus Winter
Magnus Winter

Reputation: 931

I'm pretty sure that fullCalendar actually sends the start and end times to your page as parameters.

from events as jsonfeed the example says: /myfeed.php?start=1262332800&end=1265011200 So you should probably just read these two parameters and convert them from seconds (not ms in fullCalendar!) since January 1st 1970

Upvotes: 2

Related Questions