-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #6 from bolorundurowb/feature/add-second-tranche-o…
…f-methods feature/add calendar time
- Loading branch information
Showing
10 changed files
with
450 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace moment.net.Models | ||
{ | ||
public class CalendarTimeFormats | ||
{ | ||
public string SameDay { get; } | ||
|
||
public string NextDay { get; } | ||
|
||
public string NextWeek { get; } | ||
|
||
public string LastDay { get; } | ||
|
||
public string LastWeek { get; } | ||
|
||
public string EverythingElse { get; } | ||
|
||
/// <summary> | ||
/// Default constructor, sets the time formats to the default | ||
/// </summary> | ||
public CalendarTimeFormats() | ||
{ | ||
const string baseSuffix = " 'at' hh:mm tt"; | ||
SameDay = "'Today'" + baseSuffix; | ||
NextDay = "'Tomorrow'" + baseSuffix; | ||
NextWeek = "dddd" + baseSuffix; | ||
LastDay = "'Yesterday'" + baseSuffix; | ||
LastWeek = "'Last' dddd" + baseSuffix; | ||
EverythingElse = "MM/dd/yyyy"; | ||
} | ||
|
||
/// <summary> | ||
/// Overload constructor, allows for setting the format expected for each calendar time group | ||
/// </summary> | ||
/// <param name="sameDay">Format for dates that fall on the same day</param> | ||
/// <param name="nextDay">Format for dates that fall on the next day</param> | ||
/// <param name="nextWeek">Format for dates that fall in the next week</param> | ||
/// <param name="lastDay">Format for dates that fall on the day before</param> | ||
/// <param name="lastWeek">Format for dates that fall in the preceding week</param> | ||
/// <param name="everythingElse">Format for dates that do not fall into the predefined categories</param> | ||
public CalendarTimeFormats(string sameDay, string nextDay, string nextWeek, string lastDay, string lastWeek, | ||
string everythingElse) | ||
{ | ||
SameDay = sameDay; | ||
NextDay = nextDay; | ||
NextWeek = nextWeek; | ||
LastDay = lastDay; | ||
LastWeek = lastWeek; | ||
EverythingElse = everythingElse; | ||
} | ||
} | ||
} |
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,55 @@ | ||
using System; | ||
using moment.net.Models; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace moment.net.Tests | ||
{ | ||
public class CalendarTimeTests | ||
{ | ||
[Test] | ||
public void CalendarTimeSameDay() | ||
{ | ||
var today = DateTime.Now.Date.AddHours(2); | ||
today.CalendarTime().ShouldStartWith("Today at "); | ||
} | ||
|
||
[Test] | ||
public void CalendarTimeFromYesterday() | ||
{ | ||
var yesterday = DateTime.Now.AddDays(-1); | ||
yesterday.CalendarTime().ShouldStartWith("Tomorrow at "); | ||
} | ||
|
||
[Test] | ||
public void CalendarTimeFromTomorrow() | ||
{ | ||
var tomorrow = DateTime.Now.AddDays(1); | ||
tomorrow.CalendarTime().ShouldStartWith("Yesterday at "); | ||
} | ||
|
||
[Test] | ||
public void CalendarTimeFromTwoFixedDates() | ||
{ | ||
var initialDate = new DateTime(2012,12,12); | ||
var nextDate = new DateTime(2012,12,18); | ||
initialDate.CalendarTime(nextDate).ShouldStartWith(nextDate.ToString("dddd 'at' ")); | ||
} | ||
|
||
[Test] | ||
public void CalendarTimeToTwoFixedDates() | ||
{ | ||
var earlierDate = new DateTime(2012,12,12); | ||
var laterDate = new DateTime(2012,12,18); | ||
laterDate.CalendarTime(earlierDate).ShouldStartWith(earlierDate.ToString("'Last' dddd 'at' ")); | ||
} | ||
|
||
[Test] | ||
public void CalendarTimeForEcessiveTimeSpanWithSpecifiedFormat() | ||
{ | ||
var initialDate = new DateTime(2012,12,12); | ||
var nextDate = new DateTime(2018,12,12); | ||
initialDate.CalendarTime(nextDate, new CalendarTimeFormats("", "", "", "", "", "dd/MM/yyyy")).ShouldBe(nextDate.ToString("dd/MM/yyyy")); | ||
} | ||
} | ||
} |
Oops, something went wrong.