Setting the EndDate in UTC when creating a stream


#1

Hi there,
I’m trying to create a stream using the .NET library and it seems that when I give an EndDate for a stream it get’s translated poorly to another timezone.
My code here:
var client = new DataSift.DataSiftClient(user, key);
var testParams = new { method = “post”, url = “http://81.218.208.141:8002/api/sift”, delivery_frequency = 60, max_size = 10485760 };

var compiled = client.Compile(“twitter.text contains “pakapaka””);
var endTime = DateTime.UtcNow + TimeSpan.FromHours(1);
var res = client.Push.Create(“test timezone”, “http”, testParams, hash: compiled.Data.hash, end: endTime);

while endTime is:
5/6/2015 5:22:31 PM (which is in UTC)
In res.Data.end I get 1430940151 which is:
Wed, 06 May 2015 19:22:31 GMT

Any idea what’s going on?
An I doing something wrong?


#2

Hi,

If you output DateTime.UtcNow, does it correctly reflect the current time in UTC?


#3

Yes, The DateTime.UtcNow gives the correct UTC time


#4

The DateTime.UtcNow method seems to return a DateTime object. DataSift requires that the value passed as a start or end timestamp for a Push subscription is a Unix timestamp integer (or that value as a string)


#5

We’re using the .NET plugin that accepts a DateTimeOffset object so the DateTime object is automatically casted to it.


#6

I think I figured out the problem after debugging the .NET api… there might be a bug with the conversion of the dates to UNIX time, I’ll test it out and update on the issue.


#7

OK, I changed the following method in APIHelpers class:

public static int ToUnixTime(DateTimeOffset time)
{
    return (int)(time - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
}

To that:

public static int ToUnixTime(DateTimeOffset time)
{
    return (int)(time - new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime()).TotalSeconds;
}

And it works great, this function ignored the local time hence the UNIX time calculated wasn’t accurate.