public void ToEpochTest_BeforeEpochStart() { // Arrange var date = new DateTime(1969, 12, 31, 23, 59, 59); // Act var epoch = date.ToEpoch(); // Assert epoch.Should().Be(-1, "one second less than epoch start"); }
public void ToEpochTest_EpochStart() { // Arrange var date = new DateTime(1970, 1, 1); // Act var epoch = date.ToEpoch(); // Assert epoch.Should().Be(0, "that is when epoch starts"); }
public void DateTime_ToEpoch_Should_Convert_Historical_Epoch_To_Date() { // arrange var pre_epoch_date = new DateTime(1950, 1, 1 , 10, 30, 00); var expectedEpoch = -631114200; // act var target = pre_epoch_date.ToEpoch(); // assert target.Should().Be(expectedEpoch); }
public void DateTime_ToEpoch_Should_Convert_Epoch_To_Date() { // arrange var date = new DateTime(1981, 6, 15 , 20, 30, 00); var expectedEpoch = 361485000; // act var target = date.ToEpoch(); // assert target.Should().Be(expectedEpoch); }
private TraktEpisode GetTraktEpisodeRateData(Dictionary<string,string> episode, TraktShowSummary showSummary) { if (showSummary == null || showSummary.Seasons == null || showSummary.Seasons.Count == 0) return null; string episodeTitle = GetEpisodeName(episode[IMDbFieldMapping.cTitle]); // find episode title in list of episodes from show summary if (!string.IsNullOrEmpty(episodeTitle)) { TraktShowSummary.TraktSeason.TraktEpisode match = null; foreach (var season in showSummary.Seasons) { if (match != null) continue; match = season.Episodes.FirstOrDefault(e => string.Equals(e.Title, episodeTitle, StringComparison.InvariantCultureIgnoreCase)); } if (match != null) { return new TraktEpisode { Episode = match.Episode, Season = match.Season, TVDbId = showSummary.TVDbId, Title = showSummary.Title, Year = showSummary.Year, Rating = int.Parse(episode[IMDbFieldMapping.cRating]) }; } } // we can also lookup by airDate string episodeAirDate = episode[IMDbFieldMapping.cReleaseDate]; if (!string.IsNullOrEmpty(episodeAirDate)) { // get epoch date long dateTimeEpoch = 0; try { var splitDate = episodeAirDate.Split('-'); // parse date and add 8hours for PST DateTime dateTime = new DateTime(int.Parse(splitDate[0]), int.Parse(splitDate[1]), int.Parse(splitDate[2])).AddHours(8); dateTimeEpoch = dateTime.ToEpoch(); } catch { UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true); return null; } TraktShowSummary.TraktSeason.TraktEpisode match = null; foreach (var season in showSummary.Seasons) { if (match != null) continue; match = season.Episodes.FirstOrDefault(e => e.FirstAired == dateTimeEpoch); } if (match != null) { return new TraktEpisode { Episode = match.Episode, Season = match.Season, TVDbId = match.TVDbId, Title = showSummary.Title, Year = showSummary.Year, Rating = int.Parse(episode[IMDbFieldMapping.cRating]) }; } } UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true); return null; }
public void DateTime_ToEpoch_Should_Have_Proper_StartDate() { // arrange var date = new DateTime(1970, 1, 1, 0, 0, 0); var expectedEpoch = 0; // act var target = date.ToEpoch(); // assert target.Should().Be(expectedEpoch); }
public void ToEpoch_pre_Unix() { const long numberOfSecondsUntilBeginningOfUnixEpoch = -86400; var dateTime = new DateTime(1969, 12, 31); var actual = dateTime.ToEpoch(); Assert.AreEqual(numberOfSecondsUntilBeginningOfUnixEpoch, actual); }
public void ToEpoch_post_Unix() { const long numberOfSecondsSinceBeginningOfUnixEpoch = 432000; var dateTime = new DateTime(1970, 1, 6); var actual = dateTime.ToEpoch(); Assert.AreEqual(numberOfSecondsSinceBeginningOfUnixEpoch, actual); }
public long ToEpoch_returns_expected_result(int year, int month, int day, int hour, int minute, int second, int ms) { var dateTime = new DateTime(year, month, day, hour, minute, second, ms); var epoch = dateTime.ToEpoch(); return epoch; }
public static long ToEpochMs(this DateTime datetime) { return(((long)datetime.ToEpoch()) * 1000); }
public void TestToEpochValue() { DateTime time = new DateTime(1977, 4, 4, 6, 0, 0, 0); Assert.AreEqual(229006800, time.ToEpoch()); }
public void EpochDate() { var date = new DateTime(2010, 1, 1); long result; result = date.ToEpoch(); var result2 = result.FromEpoch(); Assert.AreEqual(2010, result2.Year); Assert.AreEqual(1, result2.Day); Assert.AreEqual(1, result2.Month); }