Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created October 4, 2015 21:09
Show Gist options
  • Save tugberkugurlu/eb81ce166aaff7021ed3 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/eb81ce166aaff7021ed3 to your computer and use it in GitHub Desktop.
trying out ZonedDateTimeSerializer
var mongoDatabase1 = ConfigureAndGetMongoDatabase();
var racesCollection = mongoDatabase1.GetCollection<RaceEntity>("races");
racesCollection.Drop();
DateTimeZone london = DateTimeZoneProviders.Tzdb["Asia/Istanbul"];
LocalDateTime local = new LocalDateTime(1955, 3, 15, 0, 45, 00);
ZonedDateTime londonTime = london.AtStrictly(local);
var race = new RaceEntity("foo", londonTime, "bar");
try
{
await racesCollection.InsertOneAsync(race);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
return;
}
try
{
var race2 = await racesCollection.Find(Builders<RaceEntity>.Filter.Eq(x => x.Id, race.Id)).FirstOrDefaultAsync();
Console.WriteLine(race2.RaceDateTime == londonTime);
Console.WriteLine(race2.RaceDateTime.ToString());
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
return;
}
return;
@tugberkugurlu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment