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

Small improvements for monthly and yearly patterns #1

Open
wants to merge 2 commits 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
13 changes: 13 additions & 0 deletions .idea/.idea.IcgSoftware.RecurrenceRuleToText/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.IcgSoftware.RecurrenceRuleToText/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.IcgSoftware.RecurrenceRuleToText/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract public class RRuleTextBuilderTestBase

abstract protected void ToTextTest(string rRuleString, string readableString);

abstract protected void ToTextTestWithShortWeekday(string rRuleString, string readableString);

protected class RRuleTextBuilderTestHelper
{
private RecurrencePattern recurrencePattern;
Expand All @@ -28,15 +30,16 @@ public RRuleTextBuilderTestHelper(string rRuleString, string readableString)
ReadableResult = recurrencePattern.ToText();
}

public RRuleTextBuilderTestHelper(string rRuleString, string readableString, string culture)
public RRuleTextBuilderTestHelper(string rRuleString, string readableString, string culture, DisplayOptions options = null)
{

options = options ?? new DisplayOptions();

RRuleString = rRuleString;
ReadableString = readableString;
string rRuleStringC = RRuleTextBuilder.GetRRuleStringCorrection(rRuleString);
recurrencePattern = new RecurrencePattern(rRuleStringC);
RecreatedRRuleString = recurrencePattern.ToString();
ReadableResult = recurrencePattern.ToText(new CultureInfo(culture));
ReadableResult = recurrencePattern.ToText(new CultureInfo(culture), options);
}

public bool Result { get => ReadableString == ReadableResult; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ protected override void ToTextTest(string rRuleString, string readableString)
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

protected override void ToTextTestWithShortWeekday(string rRuleString, string readableString)
{
Debug.WriteLine("DE: " + readableString);
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "de", new DisplayOptions(){ShortWeekdays = true});
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

[TestMethod]
public void LastNumeral()
{
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-1MO", "monatlich am letzten Montag");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-2MO", "monatlich am vorletzten Montag");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-3FR", "monatlich am drittletzten Freitag");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-4SU", "monatlich am viertletzten Sonntag");

ToTextTestWithShortWeekday("RRULE:FREQ=MONTHLY;BYDAY=-1MO", "monatlich am letzten Mo");
ToTextTestWithShortWeekday("RRULE:FREQ=MONTHLY;BYDAY=-2MO", "monatlich am vorletzten Mo");
ToTextTestWithShortWeekday("RRULE:FREQ=MONTHLY;BYDAY=-3FR", "monatlich am drittletzten Fr");
ToTextTestWithShortWeekday("RRULE:FREQ=MONTHLY;BYDAY=-4SU", "monatlich am viertletzten So");
}

[TestMethod]
Expand All @@ -44,15 +56,19 @@ public void JavaRruleParser()

ToTextTest("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU", "wöchentlich am Montag, Dienstag");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU", "alle 2 Wochen am Montag, Dienstag");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU,WE,SA", "alle 2 Wochen am Montag, Dienstag, Mittwoch, Sonnabend");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU,WE,SA", "alle 2 Wochen am Montag, Dienstag, Mittwoch, Samstag");

ToTextTest("FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=5", "monatlich am 5.");
ToTextTest("FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=15", "monatlich am 15.");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=15", "alle 2 Monate am 15.");

ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=-1", "alle 2 Monate am letzten Montag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=1", "alle 2 Monate am ersten Montag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SA;BYSETPOS=3", "alle 2 Monate am dritten Sonnabend");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SA;BYSETPOS=3", "alle 2 Monate am dritten Samstag");

ToTextTestWithShortWeekday("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=-1", "alle 2 Monate am letzten Mo");
ToTextTestWithShortWeekday("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=1", "alle 2 Monate am ersten Mo");
ToTextTestWithShortWeekday("FREQ=MONTHLY;INTERVAL=2;BYDAY=SA;BYSETPOS=3", "alle 2 Monate am dritten Sa");

ToTextTest("FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1", "jährlich am 01. Januar");
ToTextTest("FREQ=YEARLY;BYMONTH=4;BYMONTHDAY=5", "jährlich am 05. April");
Expand All @@ -76,6 +92,7 @@ public void Custom()
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=2", "alle 2 Monate am zweiten Freitag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=3", "alle 2 Monate am dritten Freitag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=4", "alle 2 Monate am vierten Freitag");
ToTextTestWithShortWeekday("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=4", "alle 2 Monate am vierten Fr");
ToTextTest("FREQ=YEARLY;INTERVAL=3;BYMONTH=3,4", "alle 3 Jahre im März und April");
}

Expand Down Expand Up @@ -108,6 +125,49 @@ public void RruleJsDemoApp()
ToTextTest("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU", "alle 2 Wochen am Dienstag");
}


[TestMethod]
public void NumeralMonthlyDay()
{
ToTextTest("FREQ=MONTHLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=1", "monatlich am ersten Tag");
ToTextTest("FREQ=MONTHLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=2", "monatlich am zweiten Tag");
ToTextTest("FREQ=MONTHLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=-1", "monatlich am letzten Tag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=-1", "alle 2 Monate am letzten Tag");
}

[TestMethod]
public void NumeralMonthlyWeekday()
{
ToTextTest("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1", "monatlich am ersten Wochentag");
ToTextTest("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2", "monatlich am zweiten Wochentag");
ToTextTest("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", "monatlich am letzten Wochentag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", "alle 2 Monate am letzten Wochentag");
}

[TestMethod]
public void NumeralMonthlyWeekendDay()
{
ToTextTest("FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1", "monatlich am ersten Wochenendtag");
ToTextTest("FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=2", "monatlich am zweiten Wochenendtag");
ToTextTest("FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=-1", "monatlich am letzten Wochenendtag");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SU,SA;BYSETPOS=-1", "alle 2 Monate am letzten Wochenendtag");
}

[TestMethod]
public void YearlyDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYMONTH=1;BYSETPOS=1", "jährlich am ersten Tag im Januar");
}

[TestMethod]
public void YearlyWeekday()
{
ToTextTest("FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYMONTH=1;BYSETPOS=1", "jährlich am ersten Wochentag im Januar");
}

[TestMethod]
public void YearlyWeekendDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,SA;BYMONTH=1;BYSETPOS=1", "jährlich am ersten Wochenendtag im Januar");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IcgSoftware.RecurrenceRuleToText.UnitTest
Expand All @@ -17,6 +12,13 @@ protected override void ToTextTest(string rRuleString, string readableString)
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "en");
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

protected override void ToTextTestWithShortWeekday(string rRuleString, string readableString)
{
Debug.WriteLine("EN: " + readableString);
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "en", new DisplayOptions(){ShortWeekdays = true});
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

[TestMethod]
public void LastNumeral()
Expand Down Expand Up @@ -108,5 +110,22 @@ public void RruleJsDemoApp()
ToTextTest("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU", "every 2 weeks on Tuesday");
}

[TestMethod]
public void YearlyDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYMONTH=1;BYSETPOS=1", "every year on first day of January");
}

[TestMethod]
public void YearlyWeekday()
{
ToTextTest("FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYMONTH=1;BYSETPOS=1", "every year on first weekday of January");
}

[TestMethod]
public void YearlyWeekendDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,SA;BYMONTH=1;BYSETPOS=1", "every year on first weekend days of January");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ protected override void ToTextTest(string rRuleString, string readableString)
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "es");
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

protected override void ToTextTestWithShortWeekday(string rRuleString, string readableString)
{
Debug.WriteLine("ES: " + readableString);
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "es", new DisplayOptions(){ShortWeekdays = true});
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

[TestMethod]
public void LastNumeral()
{
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-1MO", "cada mes el último lunes");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-2MO", "cada mes el penúltimo lunes");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-3FR", "cada mes el tercer último viernes");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-4SU", "cada mes el cuarto último domingos");
ToTextTest("RRULE:FREQ=MONTHLY;BYDAY=-4SU", "cada mes el cuarto último domingo");
}

[TestMethod]
Expand All @@ -44,20 +51,20 @@ public void JavaRruleParser()

ToTextTest("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU", "cada semana los lunes, martes");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU", "cada 2 semanas los lunes, martes");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU,WE,SA", "cada 2 semanas los lunes, martes, miércoles, sábados");
ToTextTest("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU,WE,SA", "cada 2 semanas los lunes, martes, miércoles, sábado");

ToTextTest("FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=5", "cada mes el 5º");
ToTextTest("FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=15", "cada mes el 15º");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=15", "cada 2 meses el 15º");

ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=-1", "cada 2 meses el último lunes");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=1", "cada 2 meses el primer lunes");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SA;BYSETPOS=3", "cada 2 meses el tercer sábados");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=SA;BYSETPOS=3", "cada 2 meses el tercer sábado");

ToTextTest("FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1", "cada año el 1º de enero");
ToTextTest("FREQ=YEARLY;BYMONTH=4;BYMONTHDAY=5", "cada año el 5º de abril");

ToTextTest("FREQ=YEARLY;BYDAY=SU;BYSETPOS=1;BYMONTH=1", "cada año el primer domingos de enero");
ToTextTest("FREQ=YEARLY;BYDAY=SU;BYSETPOS=1;BYMONTH=1", "cada año el primer domingo de enero");
ToTextTest("FREQ=YEARLY;BYDAY=WE;BYSETPOS=-1;BYMONTH=4", "cada año el último miércoles de abril");

ToTextTest("FREQ=DAILY;INTERVAL=1;COUNT=2", "cada día un total de 2 veces");
Expand All @@ -71,7 +78,7 @@ public void Custom()
{
ToTextTest("FREQ=WEEKLY;COUNT=30;INTERVAL=1;WKST=MO;BYDAY=FR,TH,MO,TU,WE", "todos los días de la semana un total de 30 veces");
ToTextTest("FREQ=WEEKLY;COUNT=30;INTERVAL=1;WKST=MO;BYDAY=FR,TU,WE,TH", "cada semana los martes, miércoles, jueves, viernes un total de 30 veces");
ToTextTest("FREQ=WEEKLY;COUNT=30;INTERVAL=1;WKST=SU;BYDAY=FR,TU,WE,TH,SU", "cada semana los domingos, martes, miércoles, jueves, viernes un total de 30 veces");
ToTextTest("FREQ=WEEKLY;COUNT=30;INTERVAL=1;WKST=SU;BYDAY=FR,TU,WE,TH,SU", "cada semana los domingo, martes, miércoles, jueves, viernes un total de 30 veces");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=1", "cada 2 meses el primer viernes");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=2", "cada 2 meses el segundo viernes");
ToTextTest("FREQ=MONTHLY;INTERVAL=2;BYDAY=FR;BYSETPOS=3", "cada 2 meses el tercer viernes");
Expand Down Expand Up @@ -108,6 +115,22 @@ public void RruleJsDemoApp()
ToTextTest("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU", "cada 2 semanas los martes");
}


[TestMethod]
public void YearlyDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYMONTH=1;BYSETPOS=1", "cada año el primer día de enero");
}

[TestMethod]
public void YearlyWeekday()
{
ToTextTest("FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYMONTH=1;BYSETPOS=1", "cada año el primer día laborable de enero");
}

[TestMethod]
public void YearlyWeekendDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,SA;BYMONTH=1;BYSETPOS=1", "cada año el primer día del fin de semana de enero");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ protected override void ToTextTest(string rRuleString, string readableString)
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "fr");
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

protected override void ToTextTestWithShortWeekday(string rRuleString, string readableString)
{
Debug.WriteLine("FR: " + readableString);
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "fr", new DisplayOptions(){ShortWeekdays = true});
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

[TestMethod]
public void LastNumeral()
Expand Down Expand Up @@ -106,5 +113,22 @@ public void RruleJsDemoApp()
ToTextTest("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU", "toutes les 2 semaines le mardi");
}

[TestMethod]
public void YearlyDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYMONTH=1;BYSETPOS=1", "tous les ans le premier jour de janvier");
}

[TestMethod]
public void YearlyWeekday()
{
ToTextTest("FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYMONTH=1;BYSETPOS=1", "tous les ans le premier jour ouvrable de janvier");
}

[TestMethod]
public void YearlyWeekendDay()
{
ToTextTest("FREQ=YEARLY;BYDAY=SU,SA;BYMONTH=1;BYSETPOS=1", "tous les ans le premier jour du weekend de janvier");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ protected override void ToTextTest(string rRuleString, string readableString)
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

protected override void ToTextTestWithShortWeekday(string rRuleString, string readableString)
{
Debug.WriteLine("IV: " + readableString);
var rRuleTextBuilderTest = new RRuleTextBuilderTestHelper(rRuleString, readableString, "", new DisplayOptions(){ShortWeekdays = true});
Assert.IsTrue(rRuleTextBuilderTest.Result, rRuleTextBuilderTest.ResultMessage);
}

[TestMethod]
public void InvariantCulture()
{
Expand Down
7 changes: 7 additions & 0 deletions IcgSoftware.RecurrenceRuleToText/DisplayOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace IcgSoftware.RecurrenceRuleToText
{
public class DisplayOptions
{
public bool ShortWeekdays { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
<Company>IcgSoftware</Company>
<Description>Human readable extension for iCal.NET RecurrencePattern https://github.com/rianjs/ical.net</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/pt-icg/RecurrenceRuleToText</PackageProjectUrl>
<RepositoryUrl>https://github.com/pt-icg/RecurrenceRuleToText</RepositoryUrl>
<PackageProjectUrl>https://github.com/RECOMGmbH/RecurrenceRuleToText</PackageProjectUrl>
<RepositoryUrl>https://github.com/RECOMGmbH/RecurrenceRuleToText</RepositoryUrl>
<PackageTags>icalendar ical ical.net recurrence rrule recurrence-rules human-readable multi-language-support ical-net-extension c# net csharp</PackageTags>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.2.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.0.2-recom</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading