-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from realm/yg-datetime
Add support for DateTimeOffset properties
- Loading branch information
Showing
12 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal static class DateTimeOffsetExtensions | ||
{ | ||
private static readonly DateTimeOffset UnixEpoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); | ||
|
||
internal static long ToUnixTimeSeconds(this DateTimeOffset @this) | ||
{ | ||
return Convert.ToInt64((@this.ToUniversalTime() - UnixEpoch).TotalSeconds); | ||
} | ||
|
||
internal static DateTimeOffset FromUnixTimeSeconds(long seconds) | ||
{ | ||
return UnixEpoch.AddSeconds(seconds); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using NUnit.Framework; | ||
using RealmNet; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Text; | ||
using System.Linq; | ||
|
||
namespace IntegrationTests.Shared | ||
{ | ||
[TestFixture] | ||
public class DateTimeTests | ||
{ | ||
//TODO: this is ripe for refactoring across test fixture classes | ||
|
||
protected string _databasePath; | ||
protected Realm _realm; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_databasePath = Path.GetTempFileName(); | ||
_realm = Realm.GetInstance(_databasePath); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_realm.Dispose(); | ||
} | ||
|
||
[Test] | ||
public void SetAndGetPropertyTest() | ||
{ | ||
var turingsBirthday = new DateTimeOffset(1912, 6, 23, 0, 0, 0, TimeSpan.Zero); | ||
|
||
Person turing; | ||
using (var transaction = _realm.BeginWrite()) | ||
{ | ||
turing = _realm.CreateObject<Person>(); | ||
turing.FirstName = "Alan"; | ||
turing.LastName = "Turing"; | ||
turing.Birthday = turingsBirthday; | ||
transaction.Commit(); | ||
} | ||
|
||
// perform a db fetch | ||
var turingAgain = _realm.All<Person>().ToList()[0]; | ||
|
||
Assert.That(turingAgain.Birthday, Is.EqualTo(turingsBirthday)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using IntegrationTests.Shared; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace IntegrationTests.Win32 | ||
{ | ||
[TestFixture] | ||
public class Win32DateTimeTests : DateTimeTests | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters