Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Numeric fails for large numbers like phone numbers #25

Merged
merged 4 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CsuChhs.Extensions.Tests/CsuChhs.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
10 changes: 10 additions & 0 deletions CsuChhs.Extensions.Tests/StringExtensionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ public void TestTwelveHourTime()
Assert.Equal("12:00 AM", time5.ToTwelveHourTime());
}

[Fact]
public void TestIsNumeric()
{
Assert.True("97068207".IsNumeric());
}

[Fact]
public void TestIsNumericLarge()
{
Assert.True("9706820741".IsNumeric());
}

[Fact]
public void TestToUrlExtension()
Expand Down
5 changes: 1 addition & 4 deletions CsuChhs.Extensions/CsuChhs.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>CHHS Application Development Team</Authors>
<Version>1.4.6</Version>
<Version>1.4.7</Version>
<PackageProjectUrl>https://github.com/csu-chhs/CsuChhs.Extensions</PackageProjectUrl>
<Company>College of Health and Human Sciences</Company>
<PackageId>CsuChhs.Extensions</PackageId>
<PackageDescription>Extensions for .Net Projects</PackageDescription>
<RepositoryUrl>https://github.com/csu-chhs/CsuChhs.Extensions</RepositoryUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions CsuChhs.Extensions/DataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Data;
using System.Data;

namespace CsuChhs.Extensions
{
Expand Down
13 changes: 11 additions & 2 deletions CsuChhs.Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Globalization;
using System.Globalization;

namespace CsuChhs.Extensions
{
public static class DateTimeExtensions
{
/// <summary>
/// Returns true if the date time is a weekday (M - F)
/// </summary>
/// <param name="dateTimeValue"></param>
/// <returns></returns>
public static bool IsWeekday(this DateTime dateTimeValue)
{
switch (dateTimeValue.DayOfWeek)
Expand All @@ -20,6 +24,11 @@ public static bool IsWeekday(this DateTime dateTimeValue)
}
}

/// <summary>
/// Returns true if the date time is a Monday
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static bool IsMonday(this DateTime dateTime)
{
switch (dateTime.DayOfWeek)
Expand Down
34 changes: 1 addition & 33 deletions CsuChhs.Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;

namespace CsuChhs.Extensions
namespace CsuChhs.Extensions
{
public static class EnumExtensions
{
/// <summary>
/// Adds an Enumeration type method for returning the [Display(Name = "Name")]
/// from an Enumeration. Helpful when an enumeration is used on a model
/// and you need the display value somewhere in the template or in a controller.
///
/// If being called on a dynamic you need to call the method directly and pass
/// in the Enumeration
///
/// @EnumExtensions.GetDisplayName(ViewBag.student.Seeking)
///
/// If being called on a type you can simply use GetDisplayName()
///
/// Student.Seeking.GetDisplayName();
///
/// </summary>
/// <param name="enumValue"></param>
/// <returns></returns>
[Obsolete("Use Humanizer Library instead", true)]
public static string? GetDisplayName(this Enum enumValue)
{
return enumValue?.GetType()
?.GetMember(enumValue.ToString())
?.First()
?.GetCustomAttribute<DisplayAttribute>()
?.GetName();
}

/// <summary>
/// Attempts to parse and convert a string to the
/// given enum type by enum name.
Expand Down
10 changes: 6 additions & 4 deletions CsuChhs.Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;

namespace CsuChhs.Extensions
namespace CsuChhs.Extensions
{
public static class ListExtensions
{
private static readonly Random rng = new Random();

/// <summary>
/// Attempts to randomly sort the list.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
Expand Down
6 changes: 1 addition & 5 deletions CsuChhs.Extensions/NumberExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CsuChhs.Extensions
namespace CsuChhs.Extensions
{
public static class NumberExtensions
{
Expand Down
12 changes: 7 additions & 5 deletions CsuChhs.Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Globalization;
using System.Text.RegularExpressions;

namespace CsuChhs.Extensions
Expand All @@ -9,6 +8,11 @@ namespace CsuChhs.Extensions
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Transforms a formatted string time (8:00 AM) to a 24 hour time equivalent.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ToTwelveHourTime(this string value)
{
if (value.Substring(0, 1) == "0")
Expand Down Expand Up @@ -59,8 +63,6 @@ public static string ToTwelveHourTime(this string value)
}

return $"{newTime.Value}:{value.Substring(2)} {amPm2}";


}

/// <summary>
Expand Down Expand Up @@ -271,7 +273,7 @@ public static bool IsNumeric(this string value)
{
try
{
_=Int32.Parse(value);
_=long.Parse(value);
}
catch (FormatException)
{
Expand Down