Skip to content

Commit

Permalink
Added more string and DataTime extentions
Browse files Browse the repository at this point in the history
  • Loading branch information
Teodor92 committed Mar 4, 2016
1 parent 90a6c4d commit e56214c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
37 changes: 37 additions & 0 deletions Source/MoreDotNet/Extentions/DateTimeExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,42 @@ public static bool IsPast(this DateTime date)
{
return date.IsPast(DateTime.Now);
}

public static bool Between(this DateTime input, DateTime rangeBeg, DateTime rangeEnd)
{
return input.Ticks >= rangeBeg.Ticks && input.Ticks <= rangeEnd.Ticks;
}

public static int CalculateHumanAge(this DateTime dateTime)
{
var age = DateTime.Now.Year - dateTime.Year;
if (DateTime.Now < dateTime.AddYears(age))
{
age--;
}

return age;
}

public static bool WorkingDay(this DateTime date)
{
return date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday;
}

public static bool IsWeekend(this DateTime date)
{
return date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday;
}

public static DateTime NextWorkday(this DateTime date)
{
var nextDay = date;
while (!nextDay.WorkingDay())
{
nextDay = nextDay.AddDays(1);
}

return nextDay;
}
}
}
20 changes: 20 additions & 0 deletions Source/MoreDotNet/Extentions/StringExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ public static int NthIndexOf(this string str, string match, int occurrence)
return -1;
}

public static string RemoveLastCharacter(this string input)
{
return input.Substring(0, input.Length - 1);
}

public static string RemoveLast(this string input, int number)
{
return input.Substring(0, input.Length - number);
}

public static string RemoveFirstCharacter(this string input)
{
return input.Substring(1);
}

public static string RemoveFirst(this string input, int number)
{
return input.Substring(number);
}

// TODO: Test!
public static bool IsValue<T>(this string input)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/MoreDotNet/MoreDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<Compile Include="Helpers\FileHelpers.cs" />
<Compile Include="Models\CharType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wrappers\DecimalWrappers.cs" />
<Compile Include="Wrappers\DoubleWrappers.cs" />
<Compile Include="Wrappers\FloatWrappers.cs" />
<Compile Include="Wrappers\LongWarppers.cs" />
<Compile Include="Wrappers\StringWrappers.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
14 changes: 7 additions & 7 deletions Source/MoreDotNet/Wrappers/FloatWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ public static class FloatWrappers
{
public static bool IsNaN(this float input)
{
return double.IsNaN(input);
return float.IsNaN(input);
}

public static bool IsInfinity(this double input)
public static bool IsInfinity(this float input)
{
return double.IsInfinity(input);
return float.IsInfinity(input);
}

public static bool IsNegativeInfinity(this double input)
public static bool IsNegativeInfinity(this float input)
{
return double.IsNegativeInfinity(input);
return float.IsNegativeInfinity(input);
}

public static bool IsPositiveInfinity(this double input)
public static bool IsPositiveInfinity(this float input)
{
return double.IsPositiveInfinity(input);
return float.IsPositiveInfinity(input);
}
}
}

0 comments on commit e56214c

Please # to comment.