Skip to content
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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*.cs]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- run: dotnet restore
- run: dotnet build -c Release
- run: dotnet test -c Release --no-build
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/
obj/
artifacts/
*.user
*.suo
*.swp
.vscode/
16 changes: 16 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Serilog" Version="3.0.1" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="Ical.Net" Version="5.0.10" />
<PackageVersion Include="Google.Apis.Calendar.v3" Version="1.60.0.3360" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.6.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# taskblocker
# Timeboxer

A Windows-first, console-only timeboxing planner implemented in .NET 8.

## Build

```bash
./build.sh
```

## Demo

```bash
dotnet run --project src/Timeboxer.Cli demo
```
64 changes: 64 additions & 0 deletions Timeboxer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BA0DFA50-DF37-4D29-924E-5BD0DE4564B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Domain", "src\Timeboxer.Domain\Timeboxer.Domain.csproj", "{70A17E4B-CE06-40FE-84E1-0E20C226B9F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Cli", "src\Timeboxer.Cli\Timeboxer.Cli.csproj", "{9AA19A29-D4C5-4438-800A-F32E1E63E52A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Infrastructure.Google", "src\Timeboxer.Infrastructure.Google\Timeboxer.Infrastructure.Google.csproj", "{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Persistence", "src\Timeboxer.Persistence\Timeboxer.Persistence.csproj", "{B44C9688-D703-4525-A300-4D8441E17E4F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4F3BF0C0-D79B-4610-A361-7173F76A4ACA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Domain.Tests", "tests\Timeboxer.Domain.Tests\Timeboxer.Domain.Tests.csproj", "{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timeboxer.Infrastructure.Tests", "tests\Timeboxer.Infrastructure.Tests\Timeboxer.Infrastructure.Tests.csproj", "{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{70A17E4B-CE06-40FE-84E1-0E20C226B9F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70A17E4B-CE06-40FE-84E1-0E20C226B9F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70A17E4B-CE06-40FE-84E1-0E20C226B9F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70A17E4B-CE06-40FE-84E1-0E20C226B9F0}.Release|Any CPU.Build.0 = Release|Any CPU
{9AA19A29-D4C5-4438-800A-F32E1E63E52A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AA19A29-D4C5-4438-800A-F32E1E63E52A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AA19A29-D4C5-4438-800A-F32E1E63E52A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AA19A29-D4C5-4438-800A-F32E1E63E52A}.Release|Any CPU.Build.0 = Release|Any CPU
{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4}.Release|Any CPU.Build.0 = Release|Any CPU
{B44C9688-D703-4525-A300-4D8441E17E4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B44C9688-D703-4525-A300-4D8441E17E4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B44C9688-D703-4525-A300-4D8441E17E4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B44C9688-D703-4525-A300-4D8441E17E4F}.Release|Any CPU.Build.0 = Release|Any CPU
{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8}.Release|Any CPU.Build.0 = Release|Any CPU
{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{70A17E4B-CE06-40FE-84E1-0E20C226B9F0} = {BA0DFA50-DF37-4D29-924E-5BD0DE4564B5}
{9AA19A29-D4C5-4438-800A-F32E1E63E52A} = {BA0DFA50-DF37-4D29-924E-5BD0DE4564B5}
{7C7062D5-352C-4DF6-83B3-DCA9F982CAF4} = {BA0DFA50-DF37-4D29-924E-5BD0DE4564B5}
{B44C9688-D703-4525-A300-4D8441E17E4F} = {BA0DFA50-DF37-4D29-924E-5BD0DE4564B5}
{5936E8F7-7330-4A19-B7C2-EC7AD88B2CD8} = {4F3BF0C0-D79B-4610-A361-7173F76A4ACA}
{C7A550FA-1882-4E36-AC3C-EBF37ADD6BB0} = {4F3BF0C0-D79B-4610-A361-7173F76A4ACA}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dotnet restore
Dotnet build -c Release
Dotnet test -c Release
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
dotnet restore
dotnet build -c Release
dotnet test -c Release
3 changes: 3 additions & 0 deletions src/Timeboxer.Cli/CliOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Timeboxer.Cli;

public class CliOptions { }
38 changes: 38 additions & 0 deletions src/Timeboxer.Cli/Commands/DemoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.CommandLine;
using Timeboxer.Domain.Models;
using Timeboxer.Domain.Scheduling;
using Timeboxer.Domain.Export;

namespace Timeboxer.Cli.Commands;

public static class DemoCommand
{
public static Command Create()
{
var cmd = new Command("demo", "Run demo planner");
cmd.SetHandler(() =>
{
var settings = new Settings
{
WorkWindows = new Dictionary<DayOfWeek, List<(TimeSpan, TimeSpan)>>
{
[DayOfWeek.Monday] = new() { (TimeSpan.FromHours(8.5), TimeSpan.FromHours(17)) },
[DayOfWeek.Tuesday] = new() { (TimeSpan.FromHours(8.5), TimeSpan.FromHours(17)) },
[DayOfWeek.Wednesday] = new() { (TimeSpan.FromHours(8.5), TimeSpan.FromHours(17)) },
[DayOfWeek.Thursday] = new() { (TimeSpan.FromHours(8.5), TimeSpan.FromHours(17)) },
[DayOfWeek.Friday] = new() { (TimeSpan.FromHours(8.5), TimeSpan.FromHours(17)) }
}
};
var tasks = new List<TaskItem>
{
new TaskItem{ Id="T1", Title="Demo Task", EstimateMinutes=60, Deadline=DateTimeOffset.Now.AddDays(2), Priority=Priority.P1, Difficulty=Difficulty.Med, Tags=new(){"demo"}}
};
var events = new List<CalendarEvent>();
var planner = new Planner(settings);
var today = DateOnly.FromDateTime(DateTime.Now.Date);
var result = planner.Plan(tasks, events, today, today.AddDays(5));
Console.WriteLine(ConsolePrinter.Render(result.Timeboxes));
});
return cmd;
}
}
29 changes: 29 additions & 0 deletions src/Timeboxer.Cli/Commands/ImportGoogleCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.CommandLine;
using Timeboxer.Domain.Abstractions;
using Timeboxer.Infrastructure.Google;
using Timeboxer.Persistence;
using Timeboxer.Domain.Models;

namespace Timeboxer.Cli.Commands;

public static class ImportGoogleCommand
{
public static Command Create()
{
var cmd = new Command("import-google", "Import Google Calendar events");
var fromOpt = new Option<DateTime>("--from") { IsRequired = true };
var toOpt = new Option<DateTime>("--to") { IsRequired = true };
var outOpt = new Option<string>("--out") { IsRequired = true };
cmd.AddOption(fromOpt);
cmd.AddOption(toOpt);
cmd.AddOption(outOpt);
cmd.SetHandler(async (DateTime from, DateTime to, string outPath) =>
{
ICalendarProvider provider = new GoogleCalendarProvider();
var events = await provider.GetFixedEventsAsync(from, to, CancellationToken.None);
await JsonStore.SaveAsync(outPath, events);
Console.WriteLine($"Saved {events.Count} events.");
}, fromOpt, toOpt, outOpt);
return cmd;
}
}
48 changes: 48 additions & 0 deletions src/Timeboxer.Cli/Commands/PlanCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.CommandLine;
using Timeboxer.Domain.Models;
using Timeboxer.Domain.Scheduling;
using Timeboxer.Domain.Export;
using Timeboxer.Persistence;

namespace Timeboxer.Cli.Commands;

public static class PlanCommand
{
public static Command Create()
{
var cmd = new Command("plan", "Plan tasks");
var tasksOpt = new Option<string>("--tasks") { IsRequired = true };
var eventsOpt = new Option<string>("--events") { IsRequired = true };
var settingsOpt = new Option<string>("--settings") { IsRequired = true };
var fromOpt = new Option<DateTime>("--from") { IsRequired = true };
var toOpt = new Option<DateTime>("--to") { IsRequired = true };
var icsOpt = new Option<string>("--out-ics", () => string.Empty);
var textOpt = new Option<string>("--out-text", () => string.Empty);
cmd.AddOption(tasksOpt);
cmd.AddOption(eventsOpt);
cmd.AddOption(settingsOpt);
cmd.AddOption(fromOpt);
cmd.AddOption(toOpt);
cmd.AddOption(icsOpt);
cmd.AddOption(textOpt);

cmd.SetHandler(async (string tasksPath, string eventsPath, string settingsPath, DateTime from, DateTime to, string ics, string text) =>
{
var tasks = await JsonStore.LoadAsync<List<TaskItem>>(tasksPath);
var events = await JsonStore.LoadAsync<List<CalendarEvent>>(eventsPath);
var settings = await JsonStore.LoadAsync<Settings>(settingsPath);
var planner = new Planner(settings);
var result = planner.Plan(tasks, events, DateOnly.FromDateTime(from), DateOnly.FromDateTime(to));
var summary = ConsolePrinter.Render(result.Timeboxes);
Console.WriteLine(summary);
if (!string.IsNullOrWhiteSpace(ics))
await File.WriteAllTextAsync(ics, IcsExporter.Export(result.Timeboxes));
if (!string.IsNullOrWhiteSpace(text))
await File.WriteAllTextAsync(text, summary);
if (result.Overflow.Any())
Environment.ExitCode = 2;
}, tasksOpt, eventsOpt, settingsOpt, fromOpt, toOpt, icsOpt, textOpt);

return cmd;
}
}
18 changes: 18 additions & 0 deletions src/Timeboxer.Cli/Commands/SyncGoogleCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.CommandLine;

namespace Timeboxer.Cli.Commands;

public static class SyncGoogleCommand
{
public static Command Create()
{
var cmd = new Command("sync-google", "Sync plan to Google Calendar");
var icsOpt = new Option<string>("--ics") { IsRequired = true };
cmd.AddOption(icsOpt);
cmd.SetHandler((string _) =>
{
Console.WriteLine("Sync not implemented in this sample.");
}, icsOpt);
return cmd;
}
}
19 changes: 19 additions & 0 deletions src/Timeboxer.Cli/Commands/ValidateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.CommandLine;

namespace Timeboxer.Cli.Commands;

public static class ValidateCommand
{
public static Command Create()
{
var cmd = new Command("validate", "Validate a generated plan");
var planOpt = new Option<string>("--plan") { IsRequired = true };
cmd.AddOption(planOpt);
cmd.SetHandler(async (string planPath) =>
{
var text = await File.ReadAllTextAsync(planPath);
Console.WriteLine($"Plan size {text.Length} chars");
}, planOpt);
return cmd;
}
}
11 changes: 11 additions & 0 deletions src/Timeboxer.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.CommandLine;
using Timeboxer.Cli.Commands;

var root = new RootCommand("Timeboxer CLI");
root.AddCommand(PlanCommand.Create());
root.AddCommand(DemoCommand.Create());
root.AddCommand(ImportGoogleCommand.Create());
root.AddCommand(SyncGoogleCommand.Create());
root.AddCommand(ValidateCommand.Create());

return await root.InvokeAsync(args);
18 changes: 18 additions & 0 deletions src/Timeboxer.Cli/Timeboxer.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" />
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Sinks.Console" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Timeboxer.Domain/Timeboxer.Domain.csproj" />
<ProjectReference Include="../Timeboxer.Persistence/Timeboxer.Persistence.csproj" />
<ProjectReference Include="../Timeboxer.Infrastructure.Google/Timeboxer.Infrastructure.Google.csproj" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions src/Timeboxer.Domain/Abstractions/ICalendarProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Timeboxer.Domain.Models;

namespace Timeboxer.Domain.Abstractions;

public interface ICalendarProvider
{
Task<IReadOnlyList<CalendarEvent>> GetFixedEventsAsync(DateTimeOffset startInclusive, DateTimeOffset endExclusive, CancellationToken ct);
Task UpsertTimeboxesAsync(IReadOnlyList<Timebox> timeboxes, CancellationToken ct);
string ProviderName { get; }
}
6 changes: 6 additions & 0 deletions src/Timeboxer.Domain/Abstractions/IClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Timeboxer.Domain.Abstractions;

public interface IClock
{
DateTimeOffset Now { get; }
}
17 changes: 17 additions & 0 deletions src/Timeboxer.Domain/Export/ConsolePrinter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text;
using Timeboxer.Domain.Models;

namespace Timeboxer.Domain.Export;

public static class ConsolePrinter
{
public static string Render(IEnumerable<Timebox> boxes)
{
var sb = new StringBuilder();
foreach (var tb in boxes.OrderBy(b => b.Start))
{
sb.AppendLine($"{tb.Start:yyyy-MM-dd HH:mm} - {tb.End:HH:mm} | {tb.Kind} | {tb.TaskId ?? tb.Kind.ToString()} {tb.PrimaryTag}");
}
return sb.ToString();
}
}
Loading