Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
GregaMohorko committed Nov 1, 2022
2 parents 3f648e9 + e786f9a commit f508702
Show file tree
Hide file tree
Showing 21 changed files with 456 additions and 290 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Gregor Mohorko
Copyright (c) 2022 Gregor Mohorko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [Excel](src/GM.Utility/GM.Utility/ExcelUtility.cs)
- [Exception](src/GM.Utility/GM.Utility/ExceptionUtility.cs)
- [Globalization](src/GM.Utility/GM.Utility/GlobalizationUtility.cs)
- [HashCode](src/GM.Utility/GM.Utility/HashCodeUtility.cs)
- [IEnumerable](src/GM.Utility/GM.Utility/IEnumerableUtility.cs)
- [IO](src/GM.Utility/GM.Utility/IOUtility.cs)
- [Int](src/GM.Utility/GM.Utility/IntUtility.cs)
Expand All @@ -45,7 +46,10 @@
- [Statistic](src/GM.Utility/GM.Utility/StatisticUtility.cs)
- [String](src/GM.Utility/GM.Utility/StringUtility.cs)
- [Task](src/GM.Utility/GM.Utility/TaskUtility.cs)
- [ToString](src/GM.Utility/GM.Utility/ToStringUtility.cs)
- [Type](src/GM.Utility/GM.Utility/TypeUtility.cs)
- [Uri](src/GM.Utility/GM.Utility/UriUtility.cs)
- [ValueType](src/GM.Utility/GM.Utility/ValueTypeUtility.cs)
- [Wildcard](src/GM.Utility/GM.Utility/WildcardUtility.cs)
- [XML](src/GM.Utility/GM.Utility/XMLUtility.cs)

Expand Down Expand Up @@ -74,6 +78,6 @@
## Author and License
Gregor Mohorko ([www.mohorko.info](https://www.mohorko.info))

Copyright (c) 2021 Gregor Mohorko
Copyright (c) 2022 Gregor Mohorko

[MIT License](./LICENSE.md)
29 changes: 27 additions & 2 deletions src/GM.Utility/GM.Utility.Test/DateTimeUtilityTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 Grega Mohorko
Copyright (c) 2021 Gregor Mohorko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,7 +23,7 @@ MIT License
Project: GM.Utility.Test
Created: 2018-9-12
Author: GregaMohorko
Author: Gregor Mohorko
*/

using System;
Expand All @@ -34,6 +34,31 @@ namespace GM.Utility.Test
[TestClass]
public class DateTimeUtilityTest
{
[TestMethod]
public void DurationBetween()
{
const int MS_IN_ONE_DAY = 24 * 60 * 60 * 1000;

DateTime date1;
DateTime date2;
TimeSpan durationBetween;

// ascending order
date1 = new DateTime(2021, 12, 17);
date2 = new DateTime(2021, 12, 18);
durationBetween = DateTimeUtility.DurationBetween(date1, date2);
Assert.AreEqual(1, durationBetween.Days);
Assert.AreEqual(MS_IN_ONE_DAY, durationBetween.TotalMilliseconds);

// descending order
date1 = new DateTime(2021, 12, 18);
date2 = new DateTime(2021, 12, 17);
durationBetween = DateTimeUtility.DurationBetween(date1, date2);
Assert.AreEqual(1, durationBetween.Days);
Assert.AreEqual(MS_IN_ONE_DAY, durationBetween.TotalMilliseconds);

}

[TestMethod]
public void EndOfMonth()
{
Expand Down
16 changes: 9 additions & 7 deletions src/GM.Utility/GM.Utility.Test/GM.Utility.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GM.Utility.Test</RootNamespace>
<AssemblyName>GM.Utility.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
Expand All @@ -19,6 +19,7 @@
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -39,10 +40,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -57,6 +58,7 @@
<Compile Include="ArrayUtilityTest.cs" />
<Compile Include="DateTimeUtilityTest.cs" />
<Compile Include="ReflectionUtilityTest.cs" />
<Compile Include="UriUtilityTest.cs" />
<Compile Include="UtilTest.cs" />
<Compile Include="WildcardUtilityTest.cs" />
<Compile Include="StringUtilityTest.cs" />
Expand All @@ -78,8 +80,8 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" />
<Import Project="..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2019 Grega Mohorko
Copyright (c) 2022 Gregor Mohorko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,27 +22,26 @@ MIT License
SOFTWARE.
Project: GM.Utility
Created: 2017-12-19
Author: GregaMohorko
Created: 2022-03-09
Author: Gregor Mohorko
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GM.Utility
namespace GM.Utility.Test
{
/// <summary>
/// Base class for a thread-safe (creation wise) singleton class.
/// <para>It will use the parameterless constructor to create the instance.</para>
/// </summary>
/// <typeparam name="T">The type of the actual singleton class.</typeparam>
[Obsolete("This class has been moved to GM.Utility.Patterns.Singleton, please use that one. This one will be removed in the next releases.", false)]
public abstract class Singleton<T> : Patterns.Singleton<T> where T:Singleton<T>
[TestClass]
public class UriUtilityTest
{
// FIXME obsolete v1.3.1.0
// 2020-10-30
[TestMethod]
public void Combine()
{
Assert.AreEqual("http://www.google.com/additional/paths/test", UriUtility.Combine("http://www.google.com/", "/additional/paths", "test").ToString());
}
}
}
4 changes: 2 additions & 2 deletions src/GM.Utility/GM.Utility.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="2.1.2" targetFramework="net461" />
<package id="MSTest.TestFramework" version="2.1.2" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="2.2.8" targetFramework="net461" />
<package id="MSTest.TestFramework" version="2.2.8" targetFramework="net461" />
</packages>
8 changes: 4 additions & 4 deletions src/GM.Utility/GM.Utility.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2026
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GM.Utility", "GM.Utility\GM.Utility.csproj", "{0689FB8B-C7DE-4F4A-A422-05EA5E5938B4}"
EndProject
Expand All @@ -22,8 +22,8 @@ Global
{0689FB8B-C7DE-4F4A-A422-05EA5E5938B4}.Release|Any CPU.Build.0 = Release|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Release|Any CPU.Build.0 = Debug|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBE09199-2DF5-40BF-9920-A313D674E6EB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 26 additions & 1 deletion src/GM.Utility/GM.Utility/DateTimeUtility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2020 Gregor Mohorko
Copyright (c) 2022 Gregor Mohorko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,6 +39,19 @@ namespace GM.Utility
/// </summary>
public static class DateTimeUtility
{
/// <summary>
/// Calculates and returns the duration between the two specified date times.
/// <para>The order of both date times is not important.</para>
/// </summary>
/// <param name="dateTime1">The first date time. Can be before or after the second date time.</param>
/// <param name="dateTime2">The second date time. Can be before or after the first date time.</param>
public static TimeSpan DurationBetween(DateTime dateTime1, DateTime dateTime2)
{
return dateTime1 < dateTime2
? dateTime2.Subtract(dateTime1)
: dateTime1.Subtract(dateTime2);
}

/// <summary>
/// Returns the end of the current month.
/// </summary>
Expand Down Expand Up @@ -106,6 +119,18 @@ public static string GetMonthNameAbbreviated(DateTime date)
return GlobalizationUtility.GetMonthNameAbbreviated(date);
}

/// <summary>
/// Calculates the offset or difference between the time in local time zone and Coordinated Universal Time (UTC) for the current date and time.
/// <para>Uses <see cref="TimeZone.CurrentTimeZone"/> and <see cref="DateTime.Now"/>.</para>
/// </summary>
public static TimeSpan GetUtcOffsetForLocalTime()
{
TimeZoneInfo localZone = TimeZoneInfo.Local;
DateTime currentDate = DateTime.Now;

return localZone.GetUtcOffset(currentDate);
}

/// <summary>
/// Determines whether this date is in the current month.
/// <para>
Expand Down
14 changes: 0 additions & 14 deletions src/GM.Utility/GM.Utility/DecimalUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ public static decimal GetDecimals(this decimal value, int decimalCount)
return value - decimal.Truncate(value);
}

/// <summary>
/// Gets the specified number of decimals from the decimal part of this decimal number as an integer.
/// <para>If the value is negative, the returned value will also be negative (except if the returned value is zero, then the information about the sign is lost).</para>
/// </summary>
/// <param name="value">The decimal value.</param>
/// <param name="decimalCount">Number of decimals to get.</param>
[Obsolete("This method is obsolete and will be removed in the next releases, please use GetDecimalPart(this decimal, int, bool).", true)]
public static int GetDecimalPart(this decimal value, int decimalCount)
{
// FIXME obsolete v1.3.1.0
// 2020-10-30
return GetDecimalPart(value, decimalCount, false);
}

/// <summary>
/// Gets the specified number of decimals from the decimal part of this decimal number as an integer.
/// <para>If the decimal part is below 0.1, the zeros at the beginning will be omitted.</para>
Expand Down
14 changes: 0 additions & 14 deletions src/GM.Utility/GM.Utility/DoubleUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ public static double GetDecimals(this double value, int decimalCount)
return decimal.ToDouble(decimals);
}

/// <summary>
/// Gets the specified number of decimals from the decimal part of this double as an integer.
/// <para>If the value is negative, the returned value will also be negative (except if the returned value is zero, then the information about the sign is lost).</para>
/// </summary>
/// <param name="value">The double value.</param>
/// <param name="decimalCount">Number of decimals to get.</param>
[Obsolete("This method is obsolete and will be removed in next releases, please use GetDecimalPart(this double, int, bool).", true)]
public static int GetDecimalPart(this double value, int decimalCount)
{
// FIXME obsolete v1.3.1.0
// 2020-10-30
return GetDecimalPart(value, decimalCount, false);
}

/// <summary>
/// Gets the specified number of decimals from the decimal part of this double as an integer.
/// <para>If the decimal part is below 0.1, the zeros at the beginning will be omitted.</para>
Expand Down
6 changes: 2 additions & 4 deletions src/GM.Utility/GM.Utility/EmailUtility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2020 Gregor Mohorko
Copyright (c) 2022 Gregor Mohorko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -47,11 +47,9 @@ public static bool IsValid(string emailAddress)
try {
var addr = new MailAddress(emailAddress);
// host can have multiple dots (subdomains)
/*
if(addr.Host.OccurrencesOf('.') != 1) {
if(addr.Host.OccurrencesOf('.') == 0) {
return false;
}
//*/
return addr.Address == emailAddress;
} catch {
return false;
Expand Down
25 changes: 13 additions & 12 deletions src/GM.Utility/GM.Utility/GM.Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>GM.StrongNameKey.snk</AssemblyOriginatorKeyFile>
<Version>1.3.2.0</Version>
<Version>1.4.0.0</Version>
<Title>GM.Utility</Title>
<Authors>Gregor Mohorko</Authors>
<Company>Gregor Mohorko</Company>
<PackageProjectUrl>https://github.com/GregaMohorko/GM.Utility</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>utility extensions software design pattern</PackageTags>
<Description>Library with various static classes and tools that provide universally useful functions, extensions and utilities.</Description>
<Copyright>Copyright © Gregor Mohorko 2021</Copyright>
<Copyright>Copyright © Gregor Mohorko 2022</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReleaseNotes>Added WildcardUtility.
Added ExcelUtility.ExcelColumnNameToNumber.
Added ReflectionUtility.AreAllPropertiesEqual.
Added Util.CombineWithParams.
Added IEnumerableUtility.ToDictionaryFromGrouping with additional key/element selectors.
Added support for non-public properties in ReflectionUtility.SetProperty.
Improved ReflectionUtility.IsPrimitive to include other primitive types (decimal, DateTime, DateTimeOffset, TimeSpan, Guid).
Fixed an error in GMHttpClient: 'Uri string is too long'.
Fixed a bug in IEnumerableUtility.AllSame when a value selector selected a null value.</PackageReleaseNotes>
<PackageReleaseNotes>Added HashCodeUtility.
Added ToStringUtility.
Added UriUtility.
Added ValueTypeUtility.
Added to DateTimeUtility: DurationBetween, GetUtcOffsetForLocalTime.
Added to IEnumerableUtility: MinOrDefault, MaxOrDefault.
Added to XMLUtility: Deserialize.
Improved EmailUtility.IsValid.
Improved PathUtility.GetSafeFileName.
Removed deprecated methods and classes.</PackageReleaseNotes>
<AssemblyVersion>1.3.2.0</AssemblyVersion>
<FileVersion>1.3.2.0</FileVersion>
<RepositoryUrl>https://github.com/GregaMohorko/GM.Utility</RepositoryUrl>
Expand All @@ -35,7 +36,7 @@ Fixed a bug in IEnumerableUtility.AllSame when a value selector selected a null
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>


Expand Down
Loading

0 comments on commit f508702

Please sign in to comment.