Skip to content

Commit edaf826

Browse files
authored
Add extension methods option (#13)
1 parent aae223b commit edaf826

File tree

9 files changed

+104
-6
lines changed

9 files changed

+104
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ Then go ahead and consume it.
2626
var zodiacSign = Zodiac.GetZodiacSignForDate(new DateTime(1950, 2, 12));
2727
```
2828

29+
Another simpler option if all you need is the zodiac sign for a single date is:
30+
```C#
31+
var givenDateTime = new DateTime(1995, 8, 26);
32+
var zodiacSign = givenDateTime.GetZodiacSign();
33+
```
34+
2935
#### More examples
3036
[Horoscope.Zodiac](https://github.com/ClydeDz/horoscope-nuget/blob/master/Src/Horoscope.TestConsole/ZodiacExamples.cs)
3137
[Horoscope.ChineseZodiac](https://github.com/ClydeDz/horoscope-nuget/blob/master/Src/Horoscope.TestConsole/ChineseZodiacExamples.cs)

Src/Horoscope.TestConsole/ChineseZodiacExamples.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public static void ShowZodiacBasicExamples()
2828
var zodiacSignForDate = ChineseZodiac.GetZodiacSignForDate(new DateTime(1966, 2, 12));
2929
Console.WriteLine($"\nChinese zodiac sign for {new DateTime(1966, 2, 12).ToShortDateString()} is {zodiacSignForDate.ZodiacEnglishTranslation}");
3030

31+
// Another option would be:
32+
var givenDate = new DateTime(1995, 8, 26);
33+
var anotherZodiacSign = givenDate.GetChineseZodiacSign();
34+
Console.WriteLine($"\nChinese zodiac sign for {givenDate.ToShortDateString()} is {anotherZodiacSign.ZodiacEnglishTranslation}");
35+
3136
var allChineseZodiacSigns = ChineseZodiac.GetAllZodiacSigns();
3237
Console.WriteLine($"\nGet a list of all Chinese zodiac signs");
3338
foreach (var currentZodiacSign in allChineseZodiacSigns)

Src/Horoscope.TestConsole/ZodiacExamples.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public static void ShowZodiacBasicExamples()
1616
Console.WriteLine($"\nZodiac details for {new DateTime(1966, 2, 12).ToShortDateString()}");
1717
Console.WriteLine($"Name: {zodiacSign.ZodiacName} English name: {zodiacSign.ZodiacEnglishTranslation} Duration: {zodiacSign.ZodiacDuration}");
1818

19+
// Another option would be:
20+
var givenDate = new DateTime(1995, 8, 26);
21+
var anotherZodiacSign = givenDate.GetZodiacSign();
22+
Console.WriteLine($"\nZodiac details for {givenDate.ToShortDateString()}");
23+
Console.WriteLine($"Name: {anotherZodiacSign.ZodiacName} English name: {anotherZodiacSign.ZodiacEnglishTranslation} Duration: {anotherZodiacSign.ZodiacDuration}");
24+
1925
var capriconZodiacSign = Zodiac.GetZodiacSign(ZodiacSigns.Capricorn);
2026
Console.WriteLine($"\nZodiac duration for {ZodiacSigns.Capricorn}");
2127
Console.WriteLine(capriconZodiacSign.ZodiacDuration);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Horoscope.Extensions;
3+
using Xunit;
4+
5+
namespace Horoscope.Tests
6+
{
7+
public class DateTimeExtensionsTest
8+
{
9+
[Theory]
10+
[InlineData(2, 12, "Aquarius")]
11+
[InlineData(3, 3, "Pisces")]
12+
[InlineData(2, 28, "Pisces")]
13+
[InlineData(10, 23, "Scorpio")]
14+
public void GetZodiacSign_Test(int month, int day, string zodiacSign)
15+
{
16+
var dateTime = new DateTime(1950, month, day);
17+
var symbol = dateTime.GetZodiacSign();
18+
Assert.Equal(zodiacSign, symbol.ZodiacName);
19+
}
20+
21+
[Theory]
22+
[InlineData(2018, "Dog")]
23+
[InlineData(1952, "Dragon")]
24+
[InlineData(1969, "Rooster")]
25+
[InlineData(1903, "Rabbit")]
26+
public void GetChineseZodiacSign_Test(int year, string zodiacSign)
27+
{
28+
var dateTime = new DateTime(year, 4, 1);
29+
var symbol = dateTime.GetChineseZodiacSign();
30+
Assert.Equal(zodiacSign, symbol.ZodiacEnglishTranslation);
31+
}
32+
}
33+
}

Src/Horoscope.Tests/Horoscope.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="Helpers\ZodiacHelperTest.cs" />
6060
<Compile Include="Properties\AssemblyInfo.cs" />
6161
<Compile Include="ChineseZodiacTest.cs" />
62+
<Compile Include="DateTimeExtensionsTest.cs" />
6263
<Compile Include="ZodiacTest.cs" />
6364
</ItemGroup>
6465
<ItemGroup>

Src/Horoscope.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>Horoscope</id>
5-
<version>1.0.0</version>
5+
<version>1.1.0</version>
66
<title>Horoscope</title>
77
<authors>Clyde D'Souza</authors>
88
<owners>Clyde D'Souza</owners>
@@ -14,7 +14,7 @@
1414
<iconUrl>https://raw.githubusercontent.com/ClydeDz/horoscope-nuget/master/Icon.png</iconUrl>
1515
<description>A .NET library for zodiac signs. Get details on each zodiac sign, pass a date and know which zodiac sign it falls in or get a list of all zodiac signs. Now includes Chinese zodiac signs and elements!</description>
1616
<summary>A .NET library for zodiac signs. Get details on each zodiac sign, pass a date and know which zodiac sign it falls in or get a list of all zodiac signs.</summary>
17-
<releaseNotes>Enable publicy visible comments. Add contributing guidelines and a pull request template to the GitHub repository. Use new icon format. More release notes here: https://github.com/ClydeDz/horoscope-nuget/releases </releaseNotes>
17+
<releaseNotes>Add extension methods option to DateTime objects to enable simpler, easier access to the Zodiac Signs.</releaseNotes>
1818
<copyright>Copyright (c) 2018 Clyde D'Souza</copyright>
1919
<tags>horoscope zodiac development library zodiac-signs chinese-zodiac chinese-horoscope yinyang chinese-elements yin-yang</tags>
2020
<dependencies>

Src/Horoscope/DateTimeExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Horoscope.Model;
2+
using System;
3+
4+
namespace Horoscope
5+
{
6+
/// <summary>
7+
/// Enable usage of Zodiac and ChineseZodiac methods straight from DateTime instances
8+
/// </summary>
9+
public static class DateTimeExtensions
10+
{
11+
/// <summary>
12+
/// Gets the zodiac sign.
13+
/// </summary>
14+
/// <param name="dateTime">The date for which you want the zodiac sign.</param>
15+
/// <returns>A zodiac sign object.</returns>
16+
public static ZodiacModel GetZodiacSign(this DateTime dateTime) => Zodiac.GetZodiacSignForDate(dateTime);
17+
18+
/// <summary>
19+
/// Get the Chinese zodiac sign.
20+
/// </summary>
21+
/// <param name="dateTime">The date you want to query.</param>
22+
/// <returns>Returns a Chinese zodiac sign object.</returns>
23+
public static ChineseZodiacModel GetChineseZodiacSign(this DateTime dateTime) => ChineseZodiac.GetZodiacSignForDate(dateTime);
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Horoscope.Model;
2+
using System;
3+
4+
namespace Horoscope.Extensions
5+
{
6+
public static class DateTimeExtensions
7+
{
8+
/// <summary>
9+
/// Gets the zodiac sign for the date supplied.
10+
/// </summary>
11+
/// <param name="dateTime">The date for which you want the zodiac sign.</param>
12+
/// <returns>A zodiac sign object.</returns>
13+
public static ZodiacModel GetZodiacSign(this DateTime dateTime) => Zodiac.GetZodiacSignForDate(dateTime);
14+
15+
/// <summary>
16+
/// Get the Chinese zodiac sign for the supplied date.
17+
/// </summary>
18+
/// <param name="dateTime">The date you want to query.</param>
19+
/// <returns>Returns a Chinese zodiac sign object.</returns>
20+
public static ChineseZodiacModel GetChineseZodiacSign(this DateTime dateTime) => ChineseZodiac.GetZodiacSignForDate(dateTime);
21+
}
22+
}

Src/Horoscope/Horoscope.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<Authors>Clyde D'Souza</Authors>
66
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
77
<PackageId>Horoscope</PackageId>
8-
<Version>1.0.0</Version>
8+
<Version>1.1.0</Version>
99
<Company />
1010
<PackageLicenseUrl></PackageLicenseUrl>
1111
<RepositoryUrl>https://github.com/ClydeDz/horoscope-nuget</RepositoryUrl>
1212
<PackageProjectUrl>https://github.com/ClydeDz/horoscope-nuget</PackageProjectUrl>
1313
<PackageTags>horoscope zodiac development library zodiac-signs chinese-zodiac chinese-horoscope yinyang chinese-elements yin-yang</PackageTags>
1414
<Description>A .NET library for zodiac signs. Get details on each zodiac sign, pass a date and know which zodiac sign it falls in or get a list of all zodiac signs. Now includes Chinese zodiac signs and elements!</Description>
1515
<Copyright>Copyright (c) 2018 Clyde D'Souza</Copyright>
16-
<PackageReleaseNotes>Enable publicy visible comments. Add contributing guidelines and a pull request template to the GitHub repository. Use new icon format. More release notes here: https://github.com/ClydeDz/horoscope-nuget/releases</PackageReleaseNotes>
17-
<AssemblyVersion>1.0.0.0</AssemblyVersion>
18-
<FileVersion>1.0.0.0</FileVersion>
16+
<releaseNotes>Add extension methods option to DateTime objects to enable simpler, easier access to the Zodiac Signs.</releaseNotes>
17+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
18+
<FileVersion>1.1.0.0</FileVersion>
1919
<PackageIconUrl></PackageIconUrl>
2020
<Product>Horoscope</Product>
2121
<GenerateDocumentationFile>true</GenerateDocumentationFile>

0 commit comments

Comments
 (0)