├── VERSION ├── source ├── .gitignore ├── VERSION ├── GlobalAssemblyInfo.cs └── MavenThought.Epoch │ ├── Properties │ └── AssemblyInfo.cs │ ├── On.cs │ ├── DateRange.cs │ ├── MavenThought.Epoch.csproj │ └── DatesExtensions.cs ├── test ├── .gitignore └── MavenThought.Epoch.Tests │ ├── FsCheckAddin.fs │ ├── packages.config │ ├── app.config │ ├── SpanCreationTests.fs │ ├── DateExtensionsTests.fs │ ├── DateRangeTests.fs │ ├── DateCreationTests.fs │ └── MavenThought.Epoch.Tests.fsproj ├── README.md ├── .gitignore ├── template.nuspec ├── BuildTools ├── build.fsx ├── userInput.fsx ├── config.fsx ├── package.fsx ├── test.fsx └── version.fsx ├── license.markdown └── MavenThought.Epoch.sln /VERSION: -------------------------------------------------------------------------------- 1 | 0.9.5 -------------------------------------------------------------------------------- /source/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj -------------------------------------------------------------------------------- /source/VERSION: -------------------------------------------------------------------------------- 1 | 1.2.0.0 2 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Utilities to create dates and spans with a _fluent_ style. 2 | 3 | DateRange class to represent ranges of dates that can be enumerated. 4 | 5 | Read the https://github.com/maventhought/epoch/wiki for more information. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.user 3 | *.cache 4 | *.Cache 5 | packages 6 | Packages 7 | Reports 8 | nuget 9 | TestResult.xml 10 | TestResults.xml 11 | _* 12 | Upgrade* 13 | Output 14 | lib 15 | .bundle 16 | .svn 17 | pkg 18 | *.gemspec 19 | 20 | test/TestResults.xml 21 | packaging/ 22 | *nupkg 23 | .nuget/ -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/FsCheckAddin.fs: -------------------------------------------------------------------------------- 1 | namespace FsCheck.NUnit.Examples 2 | 3 | open NUnit.Core.Extensibility 4 | 5 | open FsCheck.NUnit 6 | open FsCheck.NUnit.Addin 7 | 8 | [] 9 | type FsCheckAddin() = 10 | interface IAddin with 11 | override x.Install host = 12 | let tcBuilder = new FsCheckTestCaseBuilder() 13 | host.GetExtensionPoint("TestCaseBuilders").Install(tcBuilder) 14 | true 15 | -------------------------------------------------------------------------------- /template.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @build.number@ 6 | @authors@ 7 | http://github.com/amirci/mt_commons 8 | http://github.com/amirci/mt_commons 9 | false 10 | @description@ 11 | @summary@ 12 | Copyright MavenThought Inc. 2014 13 | 14 | -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /source/GlobalAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyCompanyAttribute("MavenThought Inc.")] 6 | [assembly: AssemblyProductAttribute("Epoch is a library with helper methods and utilities")] 7 | [assembly: AssemblyCopyrightAttribute("MavenThought Inc.")] 8 | [assembly: AssemblyTrademarkAttribute("MavenThought Inc.")] 9 | [assembly: ComVisibleAttribute(false)] 10 | [assembly: AssemblyVersionAttribute("1.2.0.0")] 11 | [assembly: AssemblyFileVersionAttribute("1.2.0.0")] 12 | namespace System { 13 | internal static class AssemblyVersionInformation { 14 | internal const string Version = "1.2.0.0"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /BuildTools/build.fsx: -------------------------------------------------------------------------------- 1 | // include Fake lib 2 | #r @"../packages/FAKE/tools/FakeLib.dll" 3 | 4 | 5 | open System.IO 6 | open Fake 7 | 8 | RestorePackages() 9 | 10 | #load "./config.fsx" 11 | #load "./userInput.fsx" 12 | #load "./version.fsx" 13 | #load "./package.fsx" 14 | #load "./Test.fsx" 15 | 16 | open Config 17 | 18 | // Targets 19 | Target "Clean" (fun _ -> 20 | CleanDirs [buildDir] 21 | ) 22 | 23 | let addBuildTarget name env sln = 24 | let rebuild config = {(setParams config) with Targets = ["Rebuild"]} 25 | Target (targetWithEnv name env) (fun _ -> 26 | setBuildMode env 27 | build rebuild sln 28 | ) 29 | 30 | targets |> Seq.iter (fun t -> addBuildTarget "Epoch" t epochSln) 31 | 32 | 33 | // start build 34 | RunTargetOrDefault "Epoch:Debug" -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/SpanCreationTests.fs: -------------------------------------------------------------------------------- 1 | module MavenThought.Epoch.Tests.``Span Creation tests`` 2 | 3 | open System 4 | open FsCheck 5 | open FsCheck.NUnit 6 | open MavenThought.Epoch 7 | 8 | let mkSpan hours = new TimeSpan(hours, 0, 0) 9 | 10 | [] 11 | let ``When using minutes returns the minutes span`` some = 12 | some > 0 ==> (some .Minutes().Span = new TimeSpan(0, some, 0)) 13 | 14 | [] 15 | let ``When using hours returns the hours span`` some = 16 | some > 0 ==> (some .Hours().Span = mkSpan some) 17 | 18 | [] 19 | let ``When using days returns the days span`` some = 20 | some > 0 ==> (some .Days().Span = mkSpan (some * 24)) 21 | 22 | [] 23 | let ``When using weeks returns the weeks span`` some = 24 | some > 0 ==> (some .Weeks().Span = mkSpan (some * 24 * 7)) 25 | 26 | 27 | -------------------------------------------------------------------------------- /source/MavenThought.Epoch/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("MavenThought.Epoch")] 8 | [assembly: AssemblyDescription("Utilities to create and manipulate date and time")] 9 | 10 | // Setting ComVisible to false makes the types in this assembly not visible 11 | // to COM components. If you need to access a type in this assembly from 12 | // COM, set the ComVisible attribute to true on that type. 13 | [assembly: ComVisible(false)] 14 | 15 | // The following GUID is for the ID of the typelib if this project is exposed to COM 16 | [assembly: Guid("8873e302-3981-40e4-881a-9e6dfc13670a")] 17 | 18 | -------------------------------------------------------------------------------- /license.markdown: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 - 2015 MavenThought Inc. 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. -------------------------------------------------------------------------------- /BuildTools/userInput.fsx: -------------------------------------------------------------------------------- 1 | // include Fake lib 2 | #r @"../packages/FAKE/tools/FakeLib.dll" 3 | 4 | 5 | open Fake 6 | 7 | [] 8 | module UserInput = 9 | let changeColorTo color = System.Console.ForegroundColor <- color 10 | 11 | let resetColor = System.Console.ResetColor 12 | 13 | let confirmAction question goAheadFn = 14 | printf "%s (Y/N)" question 15 | let option = System.Console.ReadLine() 16 | match option with 17 | | "Y" -> goAheadFn() 18 | | _ -> ignore() 19 | 20 | let chooseAnOption (question: string, options: string seq) = 21 | let options = options |> List.ofSeq 22 | changeColorTo System.ConsoleColor.Blue 23 | printf "%s\n" question 24 | changeColorTo System.ConsoleColor.Yellow 25 | options |> Seq.iteri (fun i opt -> printf "%d: %s\n" (i+1) opt) 26 | let option = System.Console.ReadLine() 27 | let isValidOption chosen = chosen >= 1 && chosen <= options.Length 28 | match System.Int32.TryParse option with 29 | | true, i when isValidOption i -> Some(i-1, List.nth options (i-1)) 30 | | _ -> None 31 | 32 | -------------------------------------------------------------------------------- /BuildTools/config.fsx: -------------------------------------------------------------------------------- 1 | // include Fake lib 2 | #r @"../packages/FAKE/tools/FakeLib.dll" 3 | 4 | 5 | open Fake 6 | 7 | // Properties 8 | [] 9 | module Config = 10 | let buildDir = "./build/" 11 | let testDir = "./test/" 12 | let srcDir = "./source/" 13 | let epochSln = "MavenThought.Epoch.sln" 14 | let prjName = "MavenThought.Epoch" 15 | let prjFolder = srcDir @@ prjName 16 | let prj = prjFolder @@ prjName + ".csproj" 17 | let buildMode () = getBuildParamOrDefault "buildMode" "Release" 18 | let version = "0.0.0.0" 19 | let targetWithEnv target env = sprintf "%s:%s" target env 20 | 21 | let setBuildMode = setEnvironVar "buildMode" 22 | 23 | let targets = ["Release"; "Debug"] 24 | let debugMode () = setBuildMode "Debug" 25 | let releaseMode () = setBuildMode "Release" 26 | 27 | let setParams defaults = 28 | { defaults with 29 | Targets = ["Build"] 30 | Properties = 31 | [ 32 | "Optimize", "True" 33 | "Platform", "Any CPU" 34 | "Configuration", buildMode() 35 | ] 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /BuildTools/package.fsx: -------------------------------------------------------------------------------- 1 | #r @"../packages/FAKE/tools/FakeLib.dll" 2 | 3 | #load "./config.fsx" 4 | #load "./userInput.fsx" 5 | #load "./version.fsx" 6 | 7 | open Fake 8 | open Fake.FileSystem 9 | 10 | open Config 11 | open Version 12 | 13 | module Package = 14 | 15 | let packagingDir = "packaging " 16 | 17 | Target "Package" (fun _ -> 18 | // Copy all the package files into a package folder 19 | 20 | run "Version:Set" 21 | 22 | MSBuildRelease "" "Rebuild" [ prj ] |> ignore 23 | 24 | FileUtils.rm_rf packagingDir 25 | 26 | FileUtils.mkdir packagingDir 27 | 28 | CopyFiles 29 | (packagingDir @@ "lib" @@ "net35") 30 | [prjFolder @@ "bin" @@ "release" @@ prjName + ".dll"] 31 | 32 | NuGet (fun p -> 33 | {p with 34 | Authors = ["Amir Barylko"] 35 | Project = "MavenThought.Epoch" 36 | Description = "Utility classes to create and manipulate dates and times" 37 | OutputPath = "." 38 | Summary = "Set of classes and extensions that make date creation much easier and clear" 39 | WorkingDir = packagingDir 40 | Version = Version.Current 41 | Publish = true }) 42 | "template.nuspec" 43 | ) -------------------------------------------------------------------------------- /BuildTools/test.fsx: -------------------------------------------------------------------------------- 1 | #r @"../packages/FAKE/tools/FakeLib.dll" 2 | 3 | #load "./config.fsx" 4 | 5 | open System.IO 6 | open Fake 7 | open Config 8 | open System.Configuration 9 | 10 | let allTests = Map["Epoch", "MavenThought.Epoch.Tests"] 11 | 12 | let testFiles testPrj = sprintf "test/%s/bin/%s/*Tests.dll" testPrj (buildMode()) 13 | 14 | let runTests files = 15 | files 16 | |> NUnit (fun p -> 17 | {p with 18 | DisableShadowCopy = true 19 | OutputFile = testDir + "/TestResults.xml" }) 20 | 21 | let addTestTarget targetName testPrj = 22 | let csProj = sprintf "./test/%s/%s.csproj" testPrj testPrj 23 | let fsProj = sprintf "./test/%s/%s.fsproj" testPrj testPrj 24 | let prjFile = (if fileExists csProj then csProj else fsProj) 25 | 26 | Target ("Test:" + targetName) (fun _ -> 27 | (debugMode ()) 28 | let testParams defaults = 29 | {(setParams defaults) with 30 | Properties = 31 | [ 32 | "Configuration", buildMode() 33 | "Platform", "AnyCPU" 34 | ] 35 | } 36 | 37 | build testParams prjFile 38 | !! (testFiles testPrj) |> runTests 39 | ) 40 | 41 | 42 | Target "Test" (fun _ -> 43 | let addPrefix = (+) "Test:" 44 | allTests 45 | |> Map.iter (fun name _ -> name |> addPrefix |> run) 46 | ) 47 | 48 | allTests |> Map.iter addTestTarget 49 | 50 | -------------------------------------------------------------------------------- /source/MavenThought.Epoch/On.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MavenThought.Epoch 4 | { 5 | public static class On 6 | { 7 | public static DateTime Jan(int day, int? year = null) 8 | { 9 | return CreateDate(day, 01, year); 10 | } 11 | public static DateTime Feb(int day, int? year = null) 12 | { 13 | return CreateDate(day, 02, year); 14 | } 15 | 16 | public static DateTime Mar(int day, int? year = null) 17 | { 18 | return CreateDate(day, 03, year); 19 | } 20 | public static DateTime Apr(int day, int? year = null) 21 | { 22 | return CreateDate(day, 04, year); 23 | } 24 | public static DateTime May(int day, int? year = null) 25 | { 26 | return CreateDate(day, 05, year); 27 | } 28 | public static DateTime Jun(int day, int? year = null) 29 | { 30 | return CreateDate(day, 06, year); 31 | } 32 | public static DateTime Jul(int day, int? year = null) 33 | { 34 | return CreateDate(day, 07, year); 35 | } 36 | public static DateTime Aug(int day, int? year = null) 37 | { 38 | return CreateDate(day, 08, year); 39 | } 40 | public static DateTime Sep(int day, int? year = null) 41 | { 42 | return CreateDate(day, 09, year); 43 | } 44 | public static DateTime Oct(int day, int? year = null) 45 | { 46 | return CreateDate(day, 10, year); 47 | } 48 | 49 | public static DateTime Nov(int day, int? year = null) 50 | { 51 | return CreateDate(day, 11, year); 52 | } 53 | 54 | public static DateTime Dec(int day, int? year = null) 55 | { 56 | return CreateDate(day, 12, year); 57 | } 58 | 59 | private static DateTime CreateDate(int day, int month, int? year = null) 60 | { 61 | var theYear = year ?? DateTime.Today.Year; 62 | 63 | return new DateTime(theYear, month, day); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /source/MavenThought.Epoch/DateRange.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace MavenThought.Epoch 6 | { 7 | public class DateRange : IEnumerable, IEquatable 8 | { 9 | public DateRange(DateTime startingAt, DateTime endingAt) 10 | { 11 | this.StartDate = startingAt.Date; 12 | this.EndDate = endingAt.Date; 13 | } 14 | 15 | public DateRange(DateTime startingAt, TimeSpan span) 16 | : this(startingAt, startingAt + span) 17 | { } 18 | 19 | public DateTime StartDate { get; private set; } 20 | 21 | public DateRange NotInclusive 22 | { 23 | get { return new DateRange(this.StartDate, this.EndDate.AddDays(-1)); } 24 | } 25 | 26 | public DateTime EndDate { get; private set; } 27 | 28 | public bool Includes(DateTime date) 29 | { 30 | return this.StartDate <= date && date <= this.EndDate; 31 | } 32 | 33 | public bool Overlaps(DateRange range) 34 | { 35 | return 36 | (this.StartDate >= range.StartDate && this.StartDate < range.EndDate) || 37 | (range.StartDate >= this.StartDate && range.StartDate < this.EndDate); 38 | } 39 | 40 | public IEnumerator GetEnumerator() 41 | { 42 | var counter = this.StartDate; 43 | 44 | while (counter <= this.EndDate) 45 | { 46 | yield return counter; 47 | counter = counter.AddDays(1); 48 | } 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | public override bool Equals(object obj) 57 | { 58 | return obj is DateRange && Equals((DateRange)obj); 59 | } 60 | 61 | public override int GetHashCode() 62 | { 63 | return this.StartDate.GetHashCode() | this.EndDate.GetHashCode(); 64 | } 65 | 66 | public bool Equals(DateRange other) 67 | { 68 | return other.StartDate == this.StartDate && other.EndDate == this.EndDate; 69 | } 70 | 71 | public override string ToString() 72 | { 73 | return string.Format("({0}, {1})", this.StartDate, this.EndDate); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/DateExtensionsTests.fs: -------------------------------------------------------------------------------- 1 | module MavenThought.Epoch.Tests.``Date extensions tests`` 2 | 3 | open System 4 | open FsCheck 5 | open FsCheck.NUnit 6 | open MavenThought.Epoch 7 | 8 | let sub some fn = -some |> float |> fn 9 | let add some fn = some |> float |> fn 10 | let toDate (d:DateTime) = d.Date 11 | 12 | module ``Some time Ago extensions`` = 13 | 14 | [] 15 | let ``Returns the seconds ago`` (some:int) = 16 | some > 0 ==> (some .Seconds().Ago = (sub some DateTime.Now.AddSeconds)) 17 | 18 | [] 19 | let ``Returns the minutes ago`` (some:int) = 20 | some > 0 ==> (some .Minutes().Ago = (sub some DateTime.Now.AddMinutes)) 21 | 22 | [] 23 | let ``Returns the days ago`` (some:int) = 24 | some > 0 ==> (some .Days().Ago = (sub some DateTime.Now.AddDays)) 25 | 26 | [] 27 | let ``Returns the years ago`` (some:int) = 28 | some > 0 ==> (some .Years().Ago.Date = (-some |> DateTime.Now.AddYears |> toDate)) 29 | 30 | [] 31 | let ``Returns the months ago`` some = 32 | some > 0 ==> (some .Months().Ago.Date = (-some |> DateTime.Today.AddMonths |> toDate)) 33 | 34 | [] 35 | let ``Returns the weeks ago`` some = 36 | some > 0 ==> (some .Weeks().Ago = (sub (some*7) DateTime.Now.AddDays)) 37 | 38 | module ``Some time FromNow extensions`` = 39 | 40 | [] 41 | let ``Returns the seconds from now`` some = 42 | some > 0 ==> (some .Seconds().FromNow = (add some DateTime.Now.AddSeconds)) 43 | 44 | [] 45 | let ``Returns the minutes from now`` some = 46 | some > 0 ==> (some .Minutes().FromNow = (add some DateTime.Now.AddMinutes)) 47 | 48 | [] 49 | let ``Returns the days from now`` some = 50 | some > 0 ==> (some .Days().FromNow.Date = (add some DateTime.Today.AddDays |> toDate)) 51 | 52 | [] 53 | let ``Returns the years from now`` some = 54 | some > 0 ==> (some .Years().FromNow.Date = (some |> DateTime.Now.AddYears |> toDate)) 55 | 56 | [] 57 | let ``Returns the months from now`` some = 58 | some > 0 ==> (some .Months().FromNow.Date = (some |> DateTime.Today.AddMonths |> toDate)) 59 | 60 | [] 61 | let ``Returns the weeks from now`` some = 62 | some > 0 ==> (some .Weeks().FromNow = (add (some * 7) DateTime.Now.AddDays)) 63 | 64 | 65 | -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/DateRangeTests.fs: -------------------------------------------------------------------------------- 1 | module MavenThought.Epoch.Tests.``Date range tests`` 2 | 3 | open System 4 | open FsCheck 5 | open FsCheck.NUnit 6 | open System.Linq 7 | open MavenThought.Epoch 8 | 9 | let mkRange (sd:DateTime) (ed: DateTime) = DateRange(sd, ed) 10 | 11 | module ``Constructor using dates`` = 12 | 13 | [] 14 | let ``Creates a date range with start and end`` (sd:DateTime) (ed: DateTime) = 15 | (ed > sd) ==> lazy ( 16 | let range = mkRange sd ed 17 | range.StartDate = sd.Date && range.EndDate = ed.Date 18 | ) 19 | 20 | module ``Constructor using span`` = 21 | 22 | [] 23 | let ``Creates a date range with the specified span`` (sd:DateTime) (span: int) = 24 | (span > 1) ==> lazy ( 25 | let range = DateRange(sd, span .Days().Span) 26 | range.StartDate = sd.Date && range.EndDate = (sd.Date + TimeSpan(span, 0, 0, 0)) 27 | ) 28 | 29 | 30 | module ``#GetEnumerator method`` = 31 | let rec allDatesBetween (startDate:DateTime) (endDate:DateTime) = seq { 32 | if startDate.Date <= endDate.Date then 33 | yield startDate.Date 34 | yield! allDatesBetween (startDate.Date.AddDays(1.0)) endDate 35 | } 36 | 37 | let haveSameElements seq1 seq2 = Enumerable.SequenceEqual(seq1, seq2) 38 | 39 | [] 40 | let ``Returns all the dates in the range`` (sd:DateTime) (ed: DateTime) = 41 | (ed > sd) ==> lazy (haveSameElements (mkRange sd ed) (allDatesBetween sd ed)) 42 | 43 | 44 | module ``#NotInclusive method`` = 45 | [] 46 | let ``Changes the end date to be a day less`` (startDate:DateTime) (endDate: DateTime) = 47 | let notInc () = (mkRange startDate endDate).NotInclusive 48 | (endDate > startDate) ==> lazy (notInc().EndDate = endDate.Date.AddDays(-1.0)) 49 | 50 | 51 | module ``#Includes method`` = 52 | module ``When the date is part of the range`` = 53 | [] 54 | let ``Returns the date is included`` (sd:DateTime) (ed: DateTime) (aDate: DateTime) = 55 | (ed > sd && aDate >= sd && aDate <= ed) ==> (mkRange sd ed).Includes(aDate) 56 | 57 | module ``When the date is not part of the range`` = 58 | [] 59 | let ``Returns the date is NOT included`` (sd:DateTime) (ed: DateTime) (aDate: DateTime) = 60 | (ed > sd && (aDate < sd || aDate > ed)) ==> not ((mkRange sd ed).Includes(aDate)) 61 | -------------------------------------------------------------------------------- /BuildTools/version.fsx: -------------------------------------------------------------------------------- 1 | // include Fake lib 2 | #r @"../packages/FAKE/tools/FakeLib.dll" 3 | #load "./config.fsx" 4 | 5 | open System 6 | open Fake 7 | open Fake.AssemblyInfoFile 8 | open Fake.Git 9 | open Microsoft.FSharp.Reflection 10 | 11 | open Config 12 | 13 | [] 14 | module Version = 15 | 16 | let private unionToString (x:'a) = 17 | match FSharpValue.GetUnionFields(x, typeof<'a>) with 18 | | case, _ -> case.Name 19 | 20 | type Part = 21 | | Major 22 | | Minor 23 | | Revision 24 | | Build 25 | 26 | let private versionFile = "source/VERSION" 27 | 28 | let Current = ReadLine versionFile 29 | 30 | type VersionNumber(version:string) = 31 | let major, minor, revision, build = 32 | match version.Split '.' |> Array.map Int32.Parse with 33 | | [|a;b;c;d|] -> a, b, c, d 34 | | _ -> 0, 0, 0, 0 35 | 36 | override this.ToString () = sprintf "%d.%d.%d.%d" major minor revision build 37 | 38 | member this.Save () = WriteFile versionFile [this.ToString()] 39 | 40 | member this.Bump part = 41 | let ma, mi, re, b = match part with 42 | | Major -> major + 1, 0, 0, 0 43 | | Minor -> major, minor + 1, 0, 0 44 | | Revision -> major, minor, revision + 1, 0 45 | | Build -> major, minor, revision, build + 1 46 | 47 | let newVersion = VersionNumber (sprintf "%d.%d.%d.%d" ma mi re b) 48 | newVersion.Save() 49 | newVersion 50 | 51 | 52 | let private attributes = 53 | [Attribute.Company "MavenThought Inc." 54 | Attribute.Product "Epoch is a library with helper methods and utilities" 55 | Attribute.Copyright "MavenThought Inc." 56 | Attribute.Trademark "MavenThought Inc." 57 | Attribute.ComVisible false 58 | Attribute.Version Current 59 | Attribute.FileVersion Current 60 | ] 61 | 62 | 63 | let private printVersion (versionNumber:VersionNumber) = 64 | printfn "Current Version: %O" versionNumber 65 | 66 | Target "Version" (fun _ -> 67 | printVersion (VersionNumber (Current)) 68 | ) 69 | 70 | Target "Version:Set" (fun _ -> 71 | CreateCSharpAssemblyInfo (srcDir @@ "GlobalAssemblyInfo.cs") attributes 72 | ) 73 | 74 | [Major; Minor; Revision] |> Seq.iter (fun p -> 75 | let bumpTarget = sprintf "Version:Bump:%s" (unionToString p) 76 | Target bumpTarget (fun _ -> 77 | let oldVersionNumber = VersionNumber(version) 78 | printfn "Old Version: %O" oldVersionNumber 79 | oldVersionNumber.Bump p |> printVersion 80 | ) 81 | ) 82 | 83 | -------------------------------------------------------------------------------- /source/MavenThought.Epoch/MavenThought.Epoch.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {35E0EF69-1292-40EC-812D-18285F50FF97} 8 | Library 9 | Properties 10 | MavenThought.Epoch 11 | MavenThought.Epoch 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Properties\GlobalAssemblyInfo.cs 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | -------------------------------------------------------------------------------- /MavenThought.Epoch.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22823.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{649CE609-D209-494C-BB1F-3DDB680CBC9A}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C5E533BB-DE1C-4AAC-B6AF-91CE429706C2}" 9 | ProjectSection(SolutionItems) = preProject 10 | main\GlobalAssemblyInfo.cs = main\GlobalAssemblyInfo.cs 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{371A231F-741E-4482-81DF-856245FC9BC2}" 14 | ProjectSection(SolutionItems) = preProject 15 | .nuget\NuGet.Config = .nuget\NuGet.Config 16 | .nuget\NuGet.exe = .nuget\NuGet.exe 17 | .nuget\NuGet.targets = .nuget\NuGet.targets 18 | EndProjectSection 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildTools", "BuildTools", "{89366D8A-9A62-4097-BFD4-E9E0A3C90B4C}" 21 | ProjectSection(SolutionItems) = preProject 22 | BuildTools\build.fsx = BuildTools\build.fsx 23 | BuildTools\config.fsx = BuildTools\config.fsx 24 | BuildTools\package.fsx = BuildTools\package.fsx 25 | Rakefile.rb = Rakefile.rb 26 | BuildTools\test.fsx = BuildTools\test.fsx 27 | BuildTools\userInput.fsx = BuildTools\userInput.fsx 28 | BuildTools\version.fsx = BuildTools\version.fsx 29 | EndProjectSection 30 | EndProject 31 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MavenThought.Epoch", "source\MavenThought.Epoch\MavenThought.Epoch.csproj", "{35E0EF69-1292-40EC-812D-18285F50FF97}" 32 | EndProject 33 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MavenThought.Epoch.Tests", "test\MavenThought.Epoch.Tests\MavenThought.Epoch.Tests.fsproj", "{2767BD16-260C-46E4-B60D-C7E2E9EAA01C}" 34 | EndProject 35 | Global 36 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 37 | Debug|Any CPU = Debug|Any CPU 38 | Release|Any CPU = Release|Any CPU 39 | EndGlobalSection 40 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 41 | {35E0EF69-1292-40EC-812D-18285F50FF97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {35E0EF69-1292-40EC-812D-18285F50FF97}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {35E0EF69-1292-40EC-812D-18285F50FF97}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {35E0EF69-1292-40EC-812D-18285F50FF97}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {2767BD16-260C-46E4-B60D-C7E2E9EAA01C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {2767BD16-260C-46E4-B60D-C7E2E9EAA01C}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {2767BD16-260C-46E4-B60D-C7E2E9EAA01C}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {2767BD16-260C-46E4-B60D-C7E2E9EAA01C}.Release|Any CPU.Build.0 = Release|Any CPU 49 | EndGlobalSection 50 | GlobalSection(SolutionProperties) = preSolution 51 | HideSolutionNode = FALSE 52 | EndGlobalSection 53 | GlobalSection(NestedProjects) = preSolution 54 | {2767BD16-260C-46E4-B60D-C7E2E9EAA01C} = {649CE609-D209-494C-BB1F-3DDB680CBC9A} 55 | EndGlobalSection 56 | EndGlobal 57 | -------------------------------------------------------------------------------- /source/MavenThought.Epoch/DatesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MavenThought.Epoch 4 | { 5 | public static class DatesExtensions 6 | { 7 | public static DateTime At(this DateTime time, int hours, int minutes = 0) 8 | { 9 | return time.Date + hours.Hours().Span + minutes.Minutes().Span; 10 | } 11 | public static bool IsWeekend(this DateTime date) 12 | { 13 | return date.DayOfWeek == DayOfWeek.Sunday || date.DayOfWeek == DayOfWeek.Saturday; 14 | } 15 | 16 | public static DateTime EndOfDay(this DateTime date) 17 | { 18 | return date.BeginningOfDay().AddDays(1).AddMilliseconds(-1); 19 | } 20 | 21 | public static DateTime BeginningOfDay(this DateTime date) 22 | { 23 | return date.Date; 24 | } 25 | 26 | public static DateTimeBuilder Hour(this int number) 27 | { 28 | return number.Hours(); 29 | } 30 | public static DateTimeBuilder Hours(this int number) 31 | { 32 | return new DateTimeBuilder(number, (d, hours) => d.AddHours(hours)); 33 | } 34 | 35 | public static DateTimeBuilder Minute(this int number) 36 | { 37 | return number.Minutes(); 38 | } 39 | 40 | public static DateTimeBuilder Minutes(this int number) 41 | { 42 | return new DateTimeBuilder(number, (d, minutes) => d.AddMinutes(minutes)); 43 | } 44 | 45 | public static DateTimeBuilder Second(this int number) 46 | { 47 | return 1.Seconds(); 48 | } 49 | 50 | public static DateTimeBuilder Seconds(this int number) 51 | { 52 | return new DateTimeBuilder(number, (d, seconds) => d.AddSeconds(seconds)); 53 | } 54 | 55 | public static DateTimeBuilder Day(this int number) 56 | { 57 | return 1.Days(); 58 | } 59 | 60 | public static DateTimeBuilder Days(this int number) 61 | { 62 | return new DateTimeBuilder(number, (d, i) => d.AddDays(i)); 63 | } 64 | 65 | public static DateTimeBuilder Week(this int number) 66 | { 67 | return number.Weeks(); 68 | } 69 | 70 | public static DateTimeBuilder Weeks(this int number) 71 | { 72 | return (number*7).Days(); 73 | } 74 | 75 | public static DateTimeBuilder Month(this int number) 76 | { 77 | return 1.Months(); 78 | } 79 | 80 | public static DateTimeBuilder Months(this int number) 81 | { 82 | return new DateTimeBuilder(number, (d, i) => d.AddMonths(i)); 83 | } 84 | 85 | public static DateTimeBuilder Year(this int number) 86 | { 87 | return 1.Years(); 88 | } 89 | 90 | public static DateTimeBuilder Years(this int number) 91 | { 92 | return new DateTimeBuilder(number, (d, i) => d.AddYears(i)); 93 | } 94 | 95 | } 96 | 97 | public class DateTimeBuilder 98 | { 99 | private readonly int _number; 100 | private readonly Func _adjustFunc; 101 | 102 | public DateTimeBuilder(int number, Func adjustFunc) 103 | { 104 | _number = number; 105 | _adjustFunc = adjustFunc; 106 | } 107 | 108 | public DateTime Ago 109 | { 110 | get { return _adjustFunc(DateTime.Now, -_number); } 111 | } 112 | 113 | public DateTime FromNow 114 | { 115 | get { return _adjustFunc(DateTime.Now, _number); } 116 | } 117 | 118 | public static implicit operator TimeSpan(DateTimeBuilder builder) 119 | { 120 | return builder.Span; 121 | } 122 | 123 | public TimeSpan Span 124 | { 125 | get { return FromNow - DateTime.Now; } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/DateCreationTests.fs: -------------------------------------------------------------------------------- 1 | module MavenThought.Epoch.Tests.``Date Creation Tests Using On Month`` 2 | 3 | open System 4 | open FsCheck 5 | open FsCheck.NUnit 6 | open MavenThought.Epoch 7 | 8 | [] 9 | module Config = 10 | let currentYear = DateTime.Today.Year 11 | let dayInRange top day = day > 0 && day <= top 12 | let mkDate year month day = DateTime(year, month, day) 13 | let matchMonth month = match month with 14 | | 01 -> On.Jan, 31 15 | | 02 -> On.Feb, 28 16 | | 03 -> On.Mar, 31 17 | | 04 -> On.Apr, 30 18 | | 05 -> On.May, 31 19 | | 06 -> On.Jun, 30 20 | | 07 -> On.Jul, 31 21 | | 08 -> On.Aug, 31 22 | | 09 -> On.Sep, 30 23 | | 10 -> On.Oct, 31 24 | | 11 -> On.Nov, 30 25 | | 12 -> On.Dec, 31 26 | | _ -> On.Jul, 31 27 | 28 | module ``When called with default year`` = 29 | let createDates month day = 30 | let monthFn, top = matchMonth month 31 | dayInRange top day ==> lazy (monthFn(day) = mkDate currentYear month day) 32 | 33 | [] 34 | let ``Creates all dates in Jan`` (day:int) = createDates 01 day 35 | 36 | [] 37 | let ``Creates all dates in Feb`` (day:int) = createDates 02 day 38 | 39 | [] 40 | let ``Creates all dates in Mar`` (day:int) = createDates 03 day 41 | 42 | [] 43 | let ``Creates all dates in Apr`` (day:int) = createDates 04 day 44 | 45 | [] 46 | let ``Creates all dates in May`` (day:int) = createDates 05 day 47 | 48 | [] 49 | let ``Creates all dates in Jun`` (day:int) = createDates 06 day 50 | 51 | [] 52 | let ``Creates all dates in Jul`` (day:int) = createDates 07 day 53 | 54 | [] 55 | let ``Creates all dates in Aug`` (day:int) = createDates 08 day 56 | 57 | [] 58 | let ``Creates all dates in Sep`` (day:int) = createDates 09 day 59 | 60 | [] 61 | let ``Creates all dates in Oct`` (day:int) = createDates 10 day 62 | 63 | [] 64 | let ``Creates all dates in Nov`` (day:int) = createDates 11 day 65 | 66 | [] 67 | let ``Creates all dates in Dec`` (day:int) = createDates 12 day 68 | 69 | module ``When called with a specific year`` = 70 | let year = Nullable(2013) 71 | let mkDate month day = DateTime(year.Value, month, day) 72 | 73 | [] 74 | let ``Creates all dates in Jan`` day = 75 | dayInRange 31 day ==> lazy (On.Jan(day, year) = mkDate 01 day) 76 | 77 | [] 78 | let ``Creates all dates in Feb`` day = 79 | dayInRange 28 day ==> lazy (On.Feb(day, year) = mkDate 02 day) 80 | 81 | [] 82 | let ``Creates all dates in Mar`` day = 83 | dayInRange 31 day ==> lazy (On.Mar(day, year) = mkDate 03 day) 84 | 85 | [] 86 | let ``Creates all dates in Apr`` day = 87 | dayInRange 30 day ==> lazy (On.Apr(day, year) = mkDate 04 day) 88 | 89 | [] 90 | let ``Creates all dates in May`` day = 91 | dayInRange 31 day ==> lazy (On.May(day, year) = mkDate 05 day) 92 | 93 | [] 94 | let ``Creates all dates in Jun`` day = 95 | dayInRange 30 day ==> lazy (On.Jun(day, year) = mkDate 06 day) 96 | 97 | [] 98 | let ``Creates all dates in Jul`` day = 99 | dayInRange 31 day ==> lazy (On.Jul(day, year) = mkDate 07 day) 100 | 101 | [] 102 | let ``Creates all dates in Aug`` day = 103 | dayInRange 31 day ==> lazy (On.Aug(day, year) = mkDate 08 day) 104 | 105 | [] 106 | let ``Creates all dates in Sep`` day = 107 | dayInRange 30 day ==> lazy (On.Sep(day, year) = mkDate 09 day) 108 | 109 | [] 110 | let ``Creates all dates in Oct`` day = 111 | dayInRange 31 day ==> lazy (On.Oct(day, year) = mkDate 10 day) 112 | 113 | [] 114 | let ``Creates all dates in Nov`` day = 115 | dayInRange 30 day ==> lazy (On.Nov(day, year) = mkDate 11 day) 116 | 117 | [] 118 | let ``Creates all dates in Dec`` day = 119 | dayInRange 31 day ==> lazy (On.Dec(day, year) = mkDate 12 day) 120 | -------------------------------------------------------------------------------- /test/MavenThought.Epoch.Tests/MavenThought.Epoch.Tests.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 2767bd16-260c-46e4-b60d-c7e2e9eaa01c 9 | Library 10 | MavenThought.Commons.FSharp.Tests 11 | MavenThought.Epoch.Tests 12 | v4.5 13 | 4.3.1.0 14 | MavenThought.Epoch.Tests 15 | ..\..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | 3 26 | bin\Debug\MavenThought.Commons.FSharp.Tests.XML 27 | 28 | 29 | pdbonly 30 | true 31 | true 32 | bin\Release\ 33 | TRACE 34 | 3 35 | bin\Release\MavenThought.Commons.FSharp.Tests.XML 36 | 37 | 38 | 11 39 | 40 | 41 | 42 | 43 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 44 | 45 | 46 | 47 | 48 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ..\..\packages\FsCheck.2.0.1\lib\net45\FsCheck.dll 72 | True 73 | 74 | 75 | ..\..\packages\FsCheck.NUnit.2.0.1\lib\net45\FsCheck.NUnit.dll 76 | True 77 | 78 | 79 | ..\..\packages\FsCheck.NUnit.2.0.1\lib\net45\FsCheck.NUnit.Addin.dll 80 | True 81 | 82 | 83 | ..\..\packages\FSharp.Core.3.1.2.1\lib\net40\FSharp.Core.dll 84 | True 85 | 86 | 87 | 88 | ..\..\packages\NUnit.Runners.2.6.4\tools\lib\nunit.core.interfaces.dll 89 | 90 | 91 | ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll 92 | True 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | MavenThought.Epoch 101 | {35e0ef69-1292-40ec-812d-18285f50ff97} 102 | True 103 | 104 | 105 | 112 | --------------------------------------------------------------------------------