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

Target netstandard2.0 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
# ============== Project specific ignores
src/packages
build
/src/.vs/*
22 changes: 22 additions & 0 deletions nuget/Chronic.NetStandard.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>Chronic.Netstandard</id>
<version>0.3.2</version>
<authors>Robert Wilczynski</authors>
<owners>Robert Wilczynski</owners>
<licenseUrl>https://raw.github.com/robertwilczynski/nChronic/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/robertwilczynski/nChronic</projectUrl>
<iconUrl>https://raw.github.com/robertwilczynski/nChronic/master/doc/chronic.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A natural language date parser for .Net. A port of Ruby's chronic.</description>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright Robert Wilczynski 2011-2016</copyright>
<tags>date time parsing DateTime chronic natural language signed</tags>
</metadata>
<files>
<file src="..\src\Chronic\bin\Release\netstandard2.0\Chronic.Netstandard.dll" target="lib\netstandard2.0" />
<file src="..\src\Chronic\bin\Release\netstandard2.0\Chronic.Netstandard.pdb" target="lib\netstandard2.0" />
<file src="..\src\Chronic\**\*.cs" target="src" />
</files>
</package>
8 changes: 8 additions & 0 deletions src/Chronic/Chronic.NetStandard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

</Project>
20 changes: 13 additions & 7 deletions src/Chronic/Tags/GrabberScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ namespace Chronic
{
public class GrabberScanner : ITokenScanner
{
static readonly dynamic[] _matches = new dynamic[]
{
new { Pattern = "last", Tag = new Grabber(Grabber.Type.Last) },
new { Pattern = "next", Tag = new Grabber(Grabber.Type.Next) },
new { Pattern = "this", Tag = new Grabber(Grabber.Type.This) }
};
static readonly PatternGrabber[] _matches = new PatternGrabber[]
{
new PatternGrabber() { Pattern = "last", Tag = new Grabber(Grabber.Type.Last) },
new PatternGrabber() { Pattern = "next", Tag = new Grabber(Grabber.Type.Next) },
new PatternGrabber() { Pattern = "this", Tag = new Grabber(Grabber.Type.This) }
};

public class PatternGrabber
{
public string Pattern { get; set; }
public Grabber Tag { get; set; }
}

public IList<Token> Scan(IList<Token> tokens, Options options)
public IList<Token> Scan(IList<Token> tokens, Options options)
{
tokens.ForEach(ApplyGrabberTags);
return tokens;
Expand Down
20 changes: 13 additions & 7 deletions src/Chronic/Tags/PointerScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ namespace Chronic
{
public class PointerScanner : ITokenScanner
{
static readonly dynamic[] Patterns = new dynamic[]
{
new { Pattern = new Regex(@"\bin\b"), Tag = new Pointer(Pointer.Type.Future) },
new { Pattern = new Regex(@"\bfuture\b"), Tag = new Pointer(Pointer.Type.Future) },
new { Pattern = new Regex(@"\bpast\b"), Tag = new Pointer(Pointer.Type.Past) },
};
static readonly PatternPointer[] Patterns = new PatternPointer[]
{
new PatternPointer() { Pattern = new Regex(@"\bin\b"), Tag = new Pointer(Pointer.Type.Future) },
new PatternPointer() { Pattern = new Regex(@"\bfuture\b"), Tag = new Pointer(Pointer.Type.Future) },
new PatternPointer() { Pattern = new Regex(@"\bpast\b"), Tag = new Pointer(Pointer.Type.Past) },
};

public class PatternPointer
{
public Regex Pattern { get; set; }
public Pointer Tag { get; set; }
}

public IList<Token> Scan(IList<Token> tokens, Options options)
public IList<Token> Scan(IList<Token> tokens, Options options)
{
tokens.ForEach(ApplyTags);
return tokens;
Expand Down
135 changes: 77 additions & 58 deletions src/Chronic/Tags/Repeaters/RepeaterScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,62 +126,81 @@ static ITag ScanSeasonNames(Token token, Options options)
static readonly Regex _timePattern =
@"^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$".Compile();

static readonly List<dynamic> DayPortionPatterns = new List<dynamic>
{
new {Pattern = "^ams?$".Compile(), Portion = DayPortion.AM},
new {Pattern = "^pms?$".Compile(), Portion = DayPortion.PM},
new {Pattern = "^mornings?$".Compile(), Portion = DayPortion.MORNING},
new {Pattern = "^afternoons?$".Compile(), Portion = DayPortion.AFTERNOON},
new {Pattern = "^evenings?$".Compile(), Portion = DayPortion.EVENING},
new {Pattern = "^(night|nite)s?$".Compile(), Portion = DayPortion.NIGHT},
};

static readonly List<dynamic> DayPatterns = new List<dynamic>
{
new {Pattern ="^m[ou]n(day)?$".Compile(), Day = DayOfWeek.Monday},
new {Pattern = "^t(ue|eu|oo|u|)s(day)?$".Compile(), Day = DayOfWeek.Tuesday},
new {Pattern = "^tue$".Compile(), Day = DayOfWeek.Tuesday},
new {Pattern = "^we(dnes|nds|nns)day$".Compile(), Day = DayOfWeek.Wednesday},
new {Pattern = "^wed$".Compile(), Day = DayOfWeek.Wednesday},
new {Pattern = "^th(urs|ers)day$".Compile(), Day = DayOfWeek.Thursday},
new {Pattern = "^thu$".Compile(), Day = DayOfWeek.Thursday},
new {Pattern = "^fr[iy](day)?$".Compile(), Day = DayOfWeek.Friday},
new {Pattern = "^sat(t?[ue]rday)?$".Compile(), Day = DayOfWeek.Saturday},
new {Pattern = "^su[nm](day)?$".Compile(), Day = DayOfWeek.Sunday},
};

static readonly List<dynamic> MonthPatterns = new List<dynamic>
{
new {Pattern = "^jan\\.?(uary)?$".Compile(), Month = MonthName.January},
new {Pattern = "^feb\\.?(ruary)?$".Compile(), Month = MonthName.February},
new {Pattern = "^mar\\.?(ch)?$".Compile(), Month = MonthName.March},
new {Pattern = "^apr\\.?(il)?$".Compile(), Month = MonthName.April},
new {Pattern = "^may$".Compile(), Month = MonthName.May},
new {Pattern = "^jun\\.?e?$".Compile(), Month = MonthName.June},
new {Pattern = "^jul\\.?y?$".Compile(), Month = MonthName.July},
new {Pattern = "^aug\\.?(ust)?$".Compile(), Month = MonthName.August},
new
{
Pattern = "^sep\\.?(t\\.?|tember)?$".Compile(),
Month = MonthName.September
},
new {Pattern = "^oct\\.?(ober)?$".Compile(), Month = MonthName.October},
new {Pattern = "^nov\\.?(ember)?$".Compile(), Month = MonthName.November},
new {Pattern = "^dec\\.?(ember)?$".Compile(), Month = MonthName.December},
};

static readonly List<dynamic> UnitPatterns = new List<dynamic>
{
new { Pattern = "^years?$".Compile(), Unit = typeof(RepeaterYear) },
new { Pattern = "^seasons?$".Compile(), Unit = typeof(RepeaterSeason) },
new { Pattern = "^months?$".Compile(), Unit = typeof(RepeaterMonth) },
new { Pattern = "^fortnights?$".Compile(), Unit = typeof(RepeaterFortnight) },
new { Pattern = "^weeks?$".Compile(), Unit = typeof(RepeaterWeek) },
new { Pattern = "^weekends?$".Compile(), Unit = typeof(RepeaterWeekend) },
new { Pattern = "^days?$".Compile(), Unit = typeof(RepeaterDay) },
new { Pattern = "^hours?$".Compile(), Unit = typeof(RepeaterHour) },
new { Pattern = "^minutes?$".Compile(), Unit = typeof(RepeaterMinute) },
new { Pattern = "^seconds?$".Compile(), Unit = typeof(RepeaterSecond) }
};
}
static readonly List<PatternDayPortion> DayPortionPatterns = new List<PatternDayPortion>
{
new PatternDayPortion() {Pattern = "^ams?$".Compile(), Portion = DayPortion.AM},
new PatternDayPortion() {Pattern = "^pms?$".Compile(), Portion = DayPortion.PM},
new PatternDayPortion() {Pattern = "^mornings?$".Compile(), Portion = DayPortion.MORNING},
new PatternDayPortion() {Pattern = "^afternoons?$".Compile(), Portion = DayPortion.AFTERNOON},
new PatternDayPortion() {Pattern = "^evenings?$".Compile(), Portion = DayPortion.EVENING},
new PatternDayPortion() {Pattern = "^(night|nite)s?$".Compile(), Portion = DayPortion.NIGHT},
};
public class PatternDayPortion
{
public Regex Pattern { get; set; }
public DayPortion Portion { get; set; }
}
static readonly List<PatternDay> DayPatterns = new List<PatternDay>
{
new PatternDay() {Pattern ="^m[ou]n(day)?$".Compile(), Day = DayOfWeek.Monday},
new PatternDay() {Pattern = "^t(ue|eu|oo|u|)s(day)?$".Compile(), Day = DayOfWeek.Tuesday},
new PatternDay() {Pattern = "^tue$".Compile(), Day = DayOfWeek.Tuesday},
new PatternDay() {Pattern = "^we(dnes|nds|nns)day$".Compile(), Day = DayOfWeek.Wednesday},
new PatternDay() {Pattern = "^wed$".Compile(), Day = DayOfWeek.Wednesday},
new PatternDay() {Pattern = "^th(urs|ers)day$".Compile(), Day = DayOfWeek.Thursday},
new PatternDay() {Pattern = "^thu$".Compile(), Day = DayOfWeek.Thursday},
new PatternDay() {Pattern = "^fr[iy](day)?$".Compile(), Day = DayOfWeek.Friday},
new PatternDay() {Pattern = "^sat(t?[ue]rday)?$".Compile(), Day = DayOfWeek.Saturday},
new PatternDay() {Pattern = "^su[nm](day)?$".Compile(), Day = DayOfWeek.Sunday},
};
public class PatternDay
{
public Regex Pattern { get; set; }
public DayOfWeek Day { get; set; }
}
static readonly List<PatternMonth> MonthPatterns = new List<PatternMonth>
{
new PatternMonth() {Pattern = "^jan\\.?(uary)?$".Compile(), Month = MonthName.January},
new PatternMonth() {Pattern = "^feb\\.?(ruary)?$".Compile(), Month = MonthName.February},
new PatternMonth() {Pattern = "^mar\\.?(ch)?$".Compile(), Month = MonthName.March},
new PatternMonth() {Pattern = "^apr\\.?(il)?$".Compile(), Month = MonthName.April},
new PatternMonth() {Pattern = "^may$".Compile(), Month = MonthName.May},
new PatternMonth() {Pattern = "^jun\\.?e?$".Compile(), Month = MonthName.June},
new PatternMonth() {Pattern = "^jul\\.?y?$".Compile(), Month = MonthName.July},
new PatternMonth() {Pattern = "^aug\\.?(ust)?$".Compile(), Month = MonthName.August},
new PatternMonth()
{
Pattern = "^sep\\.?(t\\.?|tember)?$".Compile(),
Month = MonthName.September
},
new PatternMonth() {Pattern = "^oct\\.?(ober)?$".Compile(), Month = MonthName.October},
new PatternMonth() {Pattern = "^nov\\.?(ember)?$".Compile(), Month = MonthName.November},
new PatternMonth() {Pattern = "^dec\\.?(ember)?$".Compile(), Month = MonthName.December},
};

public class PatternMonth
{
public Regex Pattern { get; set; }
public MonthName Month { get; set; }
}
static readonly List<PatternUnit> UnitPatterns = new List<PatternUnit>
{
new PatternUnit() { Pattern = "^years?$".Compile(), Unit = typeof(RepeaterYear) },
new PatternUnit() { Pattern = "^seasons?$".Compile(), Unit = typeof(RepeaterSeason) },
new PatternUnit() { Pattern = "^months?$".Compile(), Unit = typeof(RepeaterMonth) },
new PatternUnit() { Pattern = "^fortnights?$".Compile(), Unit = typeof(RepeaterFortnight) },
new PatternUnit() { Pattern = "^weeks?$".Compile(), Unit = typeof(RepeaterWeek) },
new PatternUnit() { Pattern = "^weekends?$".Compile(), Unit = typeof(RepeaterWeekend) },
new PatternUnit() { Pattern = "^days?$".Compile(), Unit = typeof(RepeaterDay) },
new PatternUnit() { Pattern = "^hours?$".Compile(), Unit = typeof(RepeaterHour) },
new PatternUnit() { Pattern = "^minutes?$".Compile(), Unit = typeof(RepeaterMinute) },
new PatternUnit() { Pattern = "^seconds?$".Compile(), Unit = typeof(RepeaterSecond) }
};

public class PatternUnit
{
public Regex Pattern { get; set; }
public Type Unit { get; set; }
}
}
}
28 changes: 16 additions & 12 deletions src/Chronic/Tags/SeparatorScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ namespace Chronic
{
public class SeparatorScanner : ITokenScanner
{
static readonly dynamic[] Patterns = new dynamic[]
{
new { Pattern = @"^,$".Compile(), Tag = new SeparatorComma() },
new { Pattern = @"^and$".Compile(), Tag = new SeparatorComma() },
new { Pattern = @"^(at|@)$".Compile(), Tag = new SeparatorAt() },
new { Pattern = @"^in$".Compile(), Tag = new SeparatorIn() },
new { Pattern = @"^/$".Compile(), Tag = new SeparatorDate(Separator.Type.Slash) },
new { Pattern = @"^-$".Compile(), Tag = new SeparatorDate(Separator.Type.Dash) },
new { Pattern = @"^on$".Compile(), Tag = new SeparatorOn() },
};

public IList<Token> Scan(IList<Token> tokens, Options options)
static readonly PatternSeparator[] Patterns = new PatternSeparator[]
{
new PatternSeparator() { Pattern = @"^,$".Compile(), Tag = new SeparatorComma() },
new PatternSeparator() { Pattern = @"^and$".Compile(), Tag = new SeparatorComma() },
new PatternSeparator() { Pattern = @"^(at|@)$".Compile(), Tag = new SeparatorAt() },
new PatternSeparator() { Pattern = @"^in$".Compile(), Tag = new SeparatorIn() },
new PatternSeparator() { Pattern = @"^/$".Compile(), Tag = new SeparatorDate(Separator.Type.Slash) },
new PatternSeparator() { Pattern = @"^-$".Compile(), Tag = new SeparatorDate(Separator.Type.Dash) },
new PatternSeparator() { Pattern = @"^on$".Compile(), Tag = new SeparatorOn() },
};
public class PatternSeparator
{
public Regex Pattern { get; set; }
public Separator Tag { get; set; }
}
public IList<Token> Scan(IList<Token> tokens, Options options)
{
tokens.ForEach(ApplyTags);
return tokens;
Expand Down