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

Converted Chronic to a portable library #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
converted Chronic to a portable library
Eugen Podaru committed May 27, 2014
commit b4b2648bcfcdaca3afe6065447a7750b5b0c0dbb
18 changes: 12 additions & 6 deletions src/Chronic.Tests/Chronic.Tests.csproj
Original file line number Diff line number Diff line change
@@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Chronic.Tests</RootNamespace>
<AssemblyName>Chronic.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -23,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -31,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -65,17 +68,20 @@
<Compile Include="Parsing\BasicExpressionsTests.cs" />
<Compile Include="Parsing\NowTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Chronic\Chronic.csproj">
<Project>{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}</Project>
<Project>{3a5c2650-f416-441c-9e8a-f106e894e5ea}</Project>
<Name>Chronic</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
18 changes: 10 additions & 8 deletions src/Chronic.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chronic", "Chronic\Chronic.csproj", "{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}"
EndProject
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chronic.Tests", "Chronic.Tests\Chronic.Tests.csproj", "{9892D0C7-C2F1-49AA-9153-48F29F24867B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chronic", "Chronic\Chronic.csproj", "{3A5C2650-F416-441C-9E8A-F106E894E5EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}.Release|Any CPU.Build.0 = Release|Any CPU
{9892D0C7-C2F1-49AA-9153-48F29F24867B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9892D0C7-C2F1-49AA-9153-48F29F24867B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9892D0C7-C2F1-49AA-9153-48F29F24867B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9892D0C7-C2F1-49AA-9153-48F29F24867B}.Release|Any CPU.Build.0 = Release|Any CPU
{3A5C2650-F416-441C-9E8A-F106E894E5EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A5C2650-F416-441C-9E8A-F106E894E5EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A5C2650-F416-441C-9E8A-F106E894E5EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A5C2650-F416-441C-9E8A-F106E894E5EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
91 changes: 42 additions & 49 deletions src/Chronic/Chronic.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{39FA7DFB-2254-4DBD-AE70-4DA763B2E8AD}</ProjectGuid>
<ProjectGuid>{3A5C2650-F416-441C-9E8A-F106E894E5EA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Chronic</RootNamespace>
<AssemblyName>Chronic</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<RootNamespace>ChronicPortable</RootNamespace>
<AssemblyName>ChronicPortable</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile344</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -33,28 +34,30 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<!-- A reference to the entire .NET Framework is automatically included -->
</ItemGroup>
<ItemGroup>
<Compile Include="EndianPrecedence.cs" />
<Compile Include="Handlers\BCLDateTimeHandler.cs" />
<Compile Include="Handlers\ComplexHandler.cs" />
<Compile Include="Handlers\GRGRHandler.cs" />
<Compile Include="Handlers\MultiSRHandler.cs" />
<Compile Include="Handlers\HandlerPattern.cs" />
<Compile Include="Handlers\HandlerType.cs" />
<Compile Include="Handlers\HandlerTypePattern.cs" />
<Compile Include="Handlers\IHandler.cs" />
<Compile Include="Handlers\MultiSRHandler.cs" />
<Compile Include="Handlers\OdRmnHandler.cs" />
<Compile Include="Handlers\OdRmnSyHandler.cs" />
<Compile Include="Handlers\ORGRHandler.cs" />
<Compile Include="Handlers\ORSRHandler.cs" />
<Compile Include="Handlers\PSRHandler.cs" />
<Compile Include="Handlers\RdnRmnOdHandler.cs" />
<Compile Include="Handlers\RdnRmnSdHandler.cs" />
<Compile Include="Handlers\BCLDateTimeHandler.cs" />
<Compile Include="Handlers\Registration\EndianSpecificRegistry.cs" />
<Compile Include="Handlers\Registration\Handle.cs" />
<Compile Include="Handlers\Registration\HandlerBuilder.cs" />
<Compile Include="Handlers\Registration\HandlerRegistry.cs" />
<Compile Include="Handlers\Registration\MyHandlerRegistry.cs" />
<Compile Include="Handlers\RepeatPattern.cs" />
<Compile Include="Handlers\RGRHandler.cs" />
<Compile Include="Handlers\RHandler.cs" />
@@ -63,6 +66,7 @@
<Compile Include="Handlers\RmnOdSyHandler.cs" />
<Compile Include="Handlers\RmnSdHandler.cs" />
<Compile Include="Handlers\RmnSdOnHandler.cs" />
<Compile Include="Handlers\RmnSdSyHandler.cs" />
<Compile Include="Handlers\RmnSyHandler.cs" />
<Compile Include="Handlers\SdRmnHandler.cs" />
<Compile Include="Handlers\SdRmnSyHandler.cs" />
@@ -74,31 +78,32 @@
<Compile Include="Handlers\SRPHandler.cs" />
<Compile Include="Handlers\SyRmnOdHandler.cs" />
<Compile Include="Handlers\SySmSdHandler.cs" />
<Compile Include="Handlers\TagPattern.cs" />
<Compile Include="Handlers\Utils.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Numerizer.cs" />
<Compile Include="Options.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Range.cs" />
<Compile Include="Span.cs" />
<Compile Include="System\CollectionExtensions.cs" />
<Compile Include="System\StringExtensions.cs" />
<Compile Include="System\Time.cs" />
<Compile Include="System\TokenCollectionExtensions.cs" />
<Compile Include="Tags\TimeZone.cs" />
<Compile Include="Tags\TimeZoneScanner.cs" />
<Compile Include="Tags\Grabber.cs" />
<Compile Include="Tags\GrabberScanner.cs" />
<Compile Include="Handlers\ComplexHandler.cs" />
<Compile Include="Handlers\Registration\Handle.cs" />
<Compile Include="Handlers\Registration\HandlerBuilder.cs" />
<Compile Include="Handlers\HandlerPattern.cs" />
<Compile Include="Handlers\Registration\HandlerRegistry.cs" />
<Compile Include="Handlers\HandlerType.cs" />
<Compile Include="Handlers\IHandler.cs" />
<Compile Include="Handlers\Registration\MyHandlerRegistry.cs" />
<Compile Include="Handlers\TagPattern.cs" />
<Compile Include="Tags\Repeaters\RepeaterUnit.cs" />
<Compile Include="Tags\Repeaters\EnumRepeaterDayPortion.cs" />
<Compile Include="Tags\Repeaters\IntegerRepeaterDayPortion.cs" />
<Compile Include="Tags\Repeaters\Repeater.cs" />
<Compile Include="Tags\ITokenScanner.cs" />
<Compile Include="Tags\Ordinal.cs" />
<Compile Include="Tags\OrdinalScanner.cs" />
<Compile Include="Tags\Pointer.cs" />
<Compile Include="Tags\PointerScanner.cs" />
<Compile Include="Tags\Repeaters\DayPortion.cs" />
<Compile Include="Tags\Repeaters\EnumRepeaterDayPortion.cs" />
<Compile Include="Tags\Repeaters\IllegalStateException.cs" />
<Compile Include="Tags\Repeaters\IntegerRepeaterDayPortion.cs" />
<Compile Include="Tags\Repeaters\MonthName.cs" />
<Compile Include="Tags\Repeaters\Repeater.cs" />
<Compile Include="Tags\Repeaters\RepeaterDay.cs" />
<Compile Include="Tags\Repeaters\RepeaterDayName.cs" />
<Compile Include="Tags\Repeaters\RepeaterDayPortion.cs" />
@@ -111,16 +116,7 @@
<Compile Include="Tags\Repeaters\RepeaterSeason.cs" />
<Compile Include="Tags\Repeaters\RepeaterSecond.cs" />
<Compile Include="Tags\Repeaters\RepeaterTime.cs" />
<Compile Include="Tags\ITokenScanner.cs" />
<Compile Include="Options.cs" />
<Compile Include="Tags\Ordinal.cs" />
<Compile Include="Tags\OrdinalScanner.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Tags\Pointer.cs" />
<Compile Include="Tags\PointerScanner.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tags\Grabber.cs" />
<Compile Include="Handlers\RmnSdSyHandler.cs" />
<Compile Include="Tags\Repeaters\RepeaterUnit.cs" />
<Compile Include="Tags\Repeaters\RepeaterUnitName.cs" />
<Compile Include="Tags\Repeaters\RepeaterWeek.cs" />
<Compile Include="Tags\Repeaters\RepeaterWeekend.cs" />
@@ -131,17 +127,14 @@
<Compile Include="Tags\Separator.cs" />
<Compile Include="Tags\SeparatorComma.cs" />
<Compile Include="Tags\SeparatorScanner.cs" />
<Compile Include="Span.cs" />
<Compile Include="System\CollectionExtensions.cs" />
<Compile Include="System\StringExtensions.cs" />
<Compile Include="Tags\Tag.cs" />
<Compile Include="Tags\TimeZone.cs" />
<Compile Include="Tags\TimeZoneScanner.cs" />
<Compile Include="Tick.cs" />
<Compile Include="Token.cs" />
<Compile Include="Tokenizer.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
2 changes: 1 addition & 1 deletion src/Chronic/Handlers/RmnSdSyHandler.cs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public Span Handle(IList<Token> tokens, Options options)
var dayStart = Time.New(year, month, day);
span = Utils.DayOrTime(dayStart, timeTokens, options);
}
catch (ArgumentException e)
catch (ArgumentException)
{
span = null;
}
2 changes: 0 additions & 2 deletions src/Chronic/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,5 @@
[assembly: AssemblyCopyright("Copyright © Robert Wilczynski 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("30e233fd-aef4-48e2-a901-a2cdb19ff6b5")]
[assembly: AssemblyVersion("0.2.1.0")]
[assembly: AssemblyFileVersion("0.2.1.0")]
2 changes: 1 addition & 1 deletion src/Chronic/Span.cs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public int Width
get
{
return
(int)Math.Truncate((End.Value - Start.Value).TotalSeconds);
(int)Math.Floor(Math.Abs((End.Value - Start.Value).TotalSeconds));
}
}

2 changes: 1 addition & 1 deletion src/Chronic/System/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public static void ForEach<T, TT>(this object[,] @this, Action<T, TT> action)
for (var i = 0; i < @this.GetLength(0); i++)
{
var pattern = (T)@this[i, 0];
var replacement = (TT)Convert.ChangeType(@this[i, 1], typeof(TT));
var replacement = (TT)Convert.ChangeType(@this[i, 1], typeof(TT), null);
action(pattern, replacement);
}
}
4 changes: 2 additions & 2 deletions src/Chronic/System/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@ public static class StringExtensions
{
public static string ReplaceAll(this string @this, string pattern, string replacement)
{
return Regex.Replace(@this, pattern, replacement);
return Regex.Replace(@this, pattern, replacement);
}

public static Regex Compile(this string @this)
{
return new Regex(@this, RegexOptions.Compiled | RegexOptions.IgnoreCase);
return new Regex(@this, RegexOptions.IgnoreCase);
}

public static string LastCharacters(this string @this, int numberOfCharsToTake)
2 changes: 1 addition & 1 deletion src/Chronic/Tags/OrdinalScanner.cs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public class OrdinalScanner : ITokenScanner
{
protected static readonly Regex Pattern = new Regex(
@"^(\d*)(st|nd|rd|th)$",
RegexOptions.Singleline | RegexOptions.Compiled);
RegexOptions.Singleline);

public IList<Token> Scan(IList<Token> tokens, Options options)
{
5 changes: 2 additions & 3 deletions src/Chronic/Tags/Repeaters/RepeaterDayPortion.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public abstract class RepeaterDayPortion<T> : Repeater<T>, IRepeaterDayPortion
protected RepeaterDayPortion(T value)
: base(value)
{

}

protected abstract int GetWidth(Range range);
@@ -22,11 +22,10 @@ protected override Span NextSpan(Pointer.Type pointer)
{
var range = GetRange(Value);
DateTime rangeStart;
DateTime rangeEnd;
if (_currentSpan == null)
{
var now = Now.Value;
var nowSeconds = (long)Math.Truncate(now.TimeOfDay.TotalSeconds);
var nowSeconds = (long)Math.Floor(now.TimeOfDay.TotalSeconds);

if (nowSeconds < range.StartSecond)
{
6 changes: 3 additions & 3 deletions src/Chronic/Tags/ScalarScanner.cs
Original file line number Diff line number Diff line change
@@ -9,16 +9,16 @@ public class ScalarScanner : ITokenScanner
{
static readonly Regex _pattern = new Regex(
@"^\d*$",
RegexOptions.Singleline | RegexOptions.Compiled);
RegexOptions.Singleline);

static readonly Regex _dayPattern = new Regex(
@"^\d\d?$",
RegexOptions.Singleline | RegexOptions.Compiled);
RegexOptions.Singleline);

static readonly Regex _monthPattern = _dayPattern;
static readonly Regex _yearPattern = new Regex(
@"^([1-9]\d)?\d\d?$",
RegexOptions.Singleline | RegexOptions.Compiled);
RegexOptions.Singleline);

static readonly string[] _dayPeriods = new string[] { "am", "pm", "morning", "afternoon", "evening", "night" };