Skip to content

Commit

Permalink
Add generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Candidate committed Apr 16, 2021
1 parent 2501847 commit 705ac0d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Tzolkin.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="12" android:versionName="0.9.12" package="com.RC.Tzolkin" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="13" android:versionName="0.9.13" package="com.RC.Tzolkin" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
<application android:label="Tzolkin" android:icon="@drawable/icon"></application>
</manifest>
44 changes: 7 additions & 37 deletions src/TzolkinDate/Generics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,14 @@ module Generics=
then addDate getTzolkin length nextNum next (next :: list)
else List.rev (next :: list)

/// Return a list of Gregorian dates after `start` with the same Tzolk’in day glyph
/// `tzolkinDate`. The number of elements in the returned list is `numDates`.
/// If `start` has a Tzolk’in day glyph of `tzolkinDate` the first element is the next
/// Gregorian date with a Tzolk’in day number of `tzolkinDate` (260 days later).
///
/// Params:
/// `numDates` The number of returned dates in the list.
/// `tzolkinDate` The Tzolk’in day glyph to search for.
/// `start` The Gregorian date to start the search.
///
/// Returns:
/// A list with the next `numDates` Gregorian dates (forward in time after
/// the date `start`) that have the same Tzolk’in day glyph as `tzolkinDate`.
//let getNextList
// (referenceDate: string * ^T)
// (numDates: int)
// (tzolkinDate: ^T)
// (start: DateTime)
// =
// let rec getNextTzolkin = addDate (getNext referenceDate tzolkinDate) numDates

// getNextTzolkin 0 start []

/// Return the last Gregorian date before or the same as `start` with a Tzolk’in
/// day glyph of `tzolkinDate`.
/// If `start` has a Tzolk’in day glyph of `tzolkinDate` return the last Gregorian
/// date with a Tzolk’in day glyph of `tzolkinDate` (260 days before).
///
/// Params:
/// `tzolkinDate` The Tzolk’in day glyph to search for.
/// `start` The Gregorian date to start the search.
///
/// Returns:
/// The last Gregorian date (backwards in time before the date `start` that
/// has a Tzolk’in day glyph of `tzolkinDate`.
//let getLast referenceDate tzolkinDate start =
// let last = System.TimeSpan.FromDays -260.0 |> (+) (getNext referenceDate tzolkinDate start)
// if last = start then last + System.TimeSpan.FromDays -260.0 else last
/// day of `tzolkinDate`.
let inline internal getLast referenceDate (numElem: int) tzolkinDate start =
let last =
System.TimeSpan.FromDays (float -numElem)
|> (+) (getNext referenceDate numElem tzolkinDate start)

if last = start then last + System.TimeSpan.FromDays (float -numElem) else last

/// Return a list of Gregorian dates before `start` with the same Tzolk’in day glyph
/// `tzolkinDate`. The number of elements in the returned list is `numDates`.
Expand Down
9 changes: 1 addition & 8 deletions src/TzolkinDate/TzolkinDate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,7 @@ module TzolkinDate =
/// The last Gregorian date (backwards in time before the date `start` that
/// has a Tzolk’in date of `tzolkinDate`.
let getLast tzolkinDate start =
let last =
System.TimeSpan.FromDays -260.0
|> (+) (getNext tzolkinDate start)

if last = start then
last + System.TimeSpan.FromDays -260.0
else
last
Generics.getLast referenceDate 260 tzolkinDate start

/// Return a list of Gregorian dates before `start` with the same Tzolk’in date
/// `tzolkinDate`. The number of elements in the returned list is `numDates`.
Expand Down
6 changes: 1 addition & 5 deletions src/TzolkinDate/TzolkinGlyph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,7 @@ module TzolkinGlyph =
/// The last Gregorian date (backwards in time before the date `start` that
/// has a Tzolk’in day glyph of `tzolkinDate`.
let getLast tzolkinDate start =
let last =
System.TimeSpan.FromDays -20.
|> (+) (getNext tzolkinDate start)

if last = start then last + System.TimeSpan.FromDays -20. else last
Generics.getLast referenceDate 20 tzolkinDate start

/// Return a list of Gregorian dates before `start` with the same Tzolk’in day glyph
/// `tzolkinDate`. The number of elements in the returned list is `numDates`.
Expand Down
6 changes: 1 addition & 5 deletions src/TzolkinDate/TzolkinNumber.fs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ module TzolkinNumber =
/// The last Gregorian date (backwards in time before the date `start` that
/// has a Tzolk’in day number of `tzolkinDate`.
let getLast tzolkinDate start =
let last =
System.TimeSpan.FromDays -13.0
|> (+) (getNext tzolkinDate start)

if last = start then last + System.TimeSpan.FromDays -13.0 else last
Generics.getLast referenceDate 13 tzolkinDate start

/// Return a list of Gregorian dates before `start` with the same Tzolk’in day number
/// `tzolkinDate`. The number of elements in the returned list is `numDates`.
Expand Down

0 comments on commit 705ac0d

Please sign in to comment.