Koyomi.FSharp
1.1.1
dotnet add package Koyomi.FSharp --version 1.1.1
NuGet\Install-Package Koyomi.FSharp -Version 1.1.1
<PackageReference Include="Koyomi.FSharp" Version="1.1.1" />
paket add Koyomi.FSharp --version 1.1.1
#r "nuget: Koyomi.FSharp, 1.1.1"
// Install Koyomi.FSharp as a Cake Addin
#addin nuget:?package=Koyomi.FSharp&version=1.1.1
// Install Koyomi.FSharp as a Cake Tool
#tool nuget:?package=Koyomi.FSharp&version=1.1.1
Koyomi.FSharp
"Koyomi.FSharp" is a thin wrapper for System.DateTime
.
This can determine Japanese holidays and no configuration file or database maintenance is required.
Requirement
dotnet >= 8.0
Installation
Add Koyomi.FSharp
as a dependency in your *.fsproj
.
dotnet add Koyomi.FSharp
Usage
As a wrapper of System.DateTime
To use it like System.DateTime
, do the following.
open System
open Koyomi.FSharp
let k = DateTime(2023, 12, 1) |> Koyomi.from
Koyomi.year k // 2023
Koyomi.month k // 12
Koyomi.date k // 1
Koyomi.dayOfWeek k // DayOfWeek.Sunday
Koyomi.addYears 1 k // 2024-01-01
Koyomi.addMonths 1 k // 2023-02-01
Koyomi.addDays 1 k // 2023-01-02
Koyomi.format "yyyy/MM/dd" k // 2023/01/01
Era(Japanese)
To derive the Japanese calendar, do the following.
open System
open Koyomi.FSharp
let e = DateTime(2023, 12, 1) |> Era.from
Era.name e // 平成
Era.year e // 5
Era.nameAndYear e // 平成5年
Era.epoc e // Reiwa(Discriminated union type)
Japanese holidays
To derive the Japanese holidays, do the following.
open System
open Koyomi.FSharp
let k = DateTime(2023, 1, 1) |> Koyomi.from
Koyomi.holiday k // Some "元日"
Koyomi.isHoliday k // true
let k = DateTime(2023, 1, 10) |> Koyomi.from
Koyomi.holiday k // None
Koyomi.isHoliday k // false
Japanese calendar
To use it as a Japanese calendar, do the following.
open System
open Koyomi.FSharp
// From the specified date to today.(Include specified date)
DateTime.Now.AddDays(-10) |> Calendar.from
// From today until the specified date.(Include specified date)
DateTime.Now.AddDays(10) |> Calendar.until
// Specifiy a range.
let from = DateTime.Now.AddDays(-10)
let until = DateTime.Not.AddDays(10)
Calendar.between from until
// An inconsistent range will return an empty list.
Calendar.between until from |> List.isEmpty // true
You can also generate a calendar by specifying the year, month, or year.
open Koyomi.FSharp
// Specified year.
Calendar.ofYear DateTime.Now.Year
// Specified year and month.
Calendar.ofMonth DateTime.Now.Year DateTime.Now.Month
If you need only holidays, use ofHolidays
.
open System
open Koyomi.FSharp
DateTime.Now.Year |> Calendar.ofYear |> Calendar.ofHolidays
Note
Koyomi.FSharp only handles dates. Hours, minutes, and seconds are not handled.
Author
License
"Koyomi.FSharp" is under MIT licesnes.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- FSharp.Core (>= 8.0.100)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.