Offsets In Azure Event Hubs - azure

I have a small client application sending data to an Azure event hub, and another application reading from it.
According to https://msdn.microsoft.com/en-us/library/azure/dn789972.aspx, you can include an offset in the event hub receiver. I'm looking to include an offset in the form of the timestamp as mentioned on MSDN. Does anyone know how to do this? I can easily include the numerical string format for the offest (e.g string myOffset = "12345", but I can't seem to get the timestamp format.
Cheers

It's not clear what you mean by "can't seem to get the timestamp format", but when you create your receiver, you pass a DateTime data type to the CreateReceiver method.
public EventHubReceiver CreateReceiver(
string partitionId,
DateTime startingDateTimeUtc,
long epoch
)
See MSDN on CreateReceiver:
https://msdn.microsoft.com/en-us/library/dn790504.aspx
If you have the timestamp as a string, you might try the DateTime.Parse (or TryParse) method to get the DateTime value.
string MyString = "Aug 25, 2015";
DateTime MyDateTime = DateTime.Parse(MyString);
See more on MSDN for Parsing Time:
https://msdn.microsoft.com/en-us/library/2h3syy57(v=vs.110).aspx

Related

How to force Azure Storage Table to save DateTime in specified format

I am saving a DateTime value into Azure Table Storage. The DateTime is being parsed from unix milliseconds format like so:
DateTimeOffset.FromUnixTimeMilliseconds(milliseconds).UtcDateTime;
When I look into the table via storage explorer the DateTimes have variable length.
See Image
I was trying find out how to force the table to store the date in the following format but I wasn't able to find a way:
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"
Is there a way to force the desired format? Thanks
I was trying find out how to force the table to store the date in the
following format but I wasn't able to find a way: "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'" Is there a way to force the desired format? Thanks
This is not possible to force on Azure Table Storage. You can apply this type of logic on application code level.
Like application level you can set.
internal class Program
{
static string storageconn = "DefaultEndpointsProtocol=https;AccountName=storageaccount87819573y6;AccountKey=xxxxx;EndpointSuffix=core.windows.net";
static string table = "Datetimetable";
static string partitionkey = "Debasis Saha";
static string rowKey = "userC";
static void Main(string[] args)
{
Microsoft.Azure.Cosmos.Table.CloudStorageAccount storageAcc = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(storageconn);
Microsoft.Azure.Cosmos.Table.CloudTableClient tblclient = storageAcc.CreateCloudTableClient(new TableClientConfiguration());
Microsoft.Azure.Cosmos.Table.CloudTable table1 = tblclient.GetTableReference(table);
Console.ReadKey();
string datetime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");
Console.WriteLine(datetime);
Console.ReadKey();
}
Output :- you can pass this datetime to Azure Table Storage.

momentJS: Getting wrong timestamp from date in a different timezone

There is one time input i.e. start_time
I am trying to get timestamp in milliseconds for these inputs
let start_time = "17:05:00";
var start_date_moment = moment(start_time, "HH:mm:ss");
console.log(start_timestamp);
output is -> moment("2019-04-24T17:05:00.000")
This output remains same on server and local
But when I am trying to get unix timestamp in milliseconds in the same way
var start_timestamp = moment(start_time, "HH:mm:ss").valueOf();
On server at different timezone
console.log(start_timestamp);//1556125500000
console.log(moment(start_timestamp/1000).format('YYYY-MM-DD HH:mm:ss'); //2019-04-24 17:05:00
On local
console.log(start_timestamp);//1556105700000
console.log(moment(start_timestamp/1000).format('YYYY-MM-DD HH:mm:ss'); //2019-04-24 22:35:00
This start_timestamp value is different on local and server. But timestamp shouldn't change with timezone, it should remains same for all timezones. Please help me with this.
How to get the correct and same value at both places. I got this link some what related to this https://github.com/moment/moment/issues/2035
There is no issue with dates any particular format, issue is only with timestamp.
You need to take the offset into consideration when using moment (using timezones moment.js). Since no offset was passed in the input, the moment will be based on the time zone of the computer the code is running on, hence the different values..
Example:
var a = moment.tz("2013-11-18 11:55", "Asia/Taipei");
var b = moment.tz("2013-11-18 11:55", "America/Toronto");
a.format(); // 2013-11-18T11:55:00+08:00
b.format(); // 2013-11-18T11:55:00-05:00
a.utc().format(); // 2013-11-18T03:55Z
b.utc().format(); // 2013-11-18T16:55Z
If you change the time zone of a moment object using moment-timezone only affects the value of the local time. It does not change the moment in time being represented, and therefore does not change the underlying timestamp.
A Unix Timestamp is always based on UTC - you can see it as the same timestamp at any given location in the world.
Official Moment Docs on timezones
Edit:
If you use utcOffset you should pass an integer:
Example:
moment.utc("2015-10-01 01:24:21").utcOffset("-240").format('YYYYMMDD HHmmss ZZ')
// "20151001 012421 +0000"
moment.utc("2015-10-01 01:24:21").utcOffset(-240).format('YYYYMMDD HHmmss ZZ')
// "20150930 212421 -0400"
MomentJS allows offset-arguments to be passed as string, but it expects the string to be in one of the ISO8601 formats: [+/-]HH:mm or [+/-]HHmm.
To avoid this all together you could, if known, pass the location as an argument like
moment.tz(start_time, "HH:mm:ss", "Asia/Kolkata").valueOf();
as mentioned in the first example above..

Using datetime in SharePoint

I have a date time item in a list that I want to interact with. I access the items in the list via SPListItem.
My code:
_relevantDate = (DateTime)_siteInfo["cimKeyDocumentDate"];
What the code means in terms of types etc:
[datetime property] = [datetime cast]SPListItem[field name];
I'm aware of the SPFieldDateTime type but I can't see a type it returns and I am confused at how I should do return the datetime.
Thanks.
Your first code would return datetime type after correct casting.
DateTime myDateTime = DateTime.Parse(myListItem["MyDateField"].ToString());
but if you want to use SPFieldDateTime then you will have to write it like
SPFieldDateTime myDateTime =(SPFieldDateTime)web.Fields[FieldNames.DateFieldName];
This will return a field that contains date and time values.See here.

PubNub message format in callbacks

When I get a callback, I get an object passed in. The content of the object seems to have two levels of 'encoding'. It always seems to consist of 3 basic elements:
My data
Timestamp
Channel
in that order so [0]=data, [1] = timestamp and [2] = channel where timestamp and channel are PubNub supplied strings. My data comes in as a JSON object (string, numeric, or object etc.) in the first item returned.
But nowhere can I find in the documentation that this structure (i.e. 3 incoming 'objects') is actually defined. If it is defined then I should be able to map a type or class to it, to better handle it, i.e. cast it to a 'PubNubMessage' class [object data; string timestamp; string channel;]?
Can someone please point me at a document where this message format is actually defined?

MOSS 2007: SPListItem.GetFormattedValue for DateTime fields has a bug?

SPListItem.GetFormattedValue seems to have a strange behavior for DateTime fields.
It retrieves the DateTime value through SPListItem's indexer which according to this MSDN article returns local time.
Here's a snippet from Reflector
public string GetFormattedValue(string fieldName)
{
SPField field = this.Fields.GetField(fieldName);
if (field != null)
{
return field.GetFieldValueAsHtml(this[fieldName]);
}
return null;
}
So it uses SPListItem's indexer to retrieve the value and than SPFields.GetFieldValueAsHtml to format the value. GetFieldValueAsHtml seems to assume the date is in UTC and convert it to local time no matter what kind it is. (Reflector shows that it uses GetFieldValueAsText which uses value.ToString() but for some reason it assumes the time to be UTC.)
The end result is that the string representation on a time field obtained trough listItem.GetFormattedValue() (at least in my case) is incorrect, being local time + (local time - UTC).
Have anybody encountered the same issue with SPListItem.GetFormattedValue() and what was your workaround?
Converting the date back to universal time before calling GetFieldValueAsHtml works just fine.
DateTime localTime = (DateTime)item["DueDate"];
// this is local time but if you do localDateTime.Kind it returns Unspecified
// treats the date as universal time..
// let's give it the universal time :)
DateTime universalTime = SPContext.Current.Web
.RegionalSettings.TimeZone.LocalTimeToUTC(localTime);
string correctFormattedValue =
item.Fields["DueDate"].GetFieldValueAsHtml(universalTime);
I have had a recognised bug with the date conversion from UTC in SharePoint. It was fixed in SP1.

Resources