summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-09-03 21:37:35 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2015-09-03 21:37:35 +0100
commit4fefdb4d916447e5378e8ac97d6cc6c20d4667b7 (patch)
tree956ef9a6f6aafa293a2878495d4b62b54efdcd02 /lib
parenta373bdd0c973fd1db2ab988aea8bcfc3d8dd4245 (diff)
parentef5f0b1ac971c0d3ce00d7c839812c6065a81334 (diff)
downloadNim-4fefdb4d916447e5378e8ac97d6cc6c20d4667b7.tar.gz
Merge pull request #3281 from nanoant/patch/lib-pure-times-hotfix
times: Export & document countLeapYears/Years/Days
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/times.nim32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 6d45dc7f1..aa4ae5ace 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -1051,26 +1051,30 @@ proc parse*(value, layout: string): TimeInfo =
   return info
 
 # Leap year calculations are adapted from:
-# from http://www.codeproject.com/Articles/7358/Ultra-fast-Algorithms-for-Working-with-Leap-Years
+# http://www.codeproject.com/Articles/7358/Ultra-fast-Algorithms-for-Working-with-Leap-Years
 # The dayOfTheWeek procs are adapated from:
-# from http://stason.org/TULARC/society/calendars/2-5-What-day-of-the-week-was-2-August-1953.html
+# http://stason.org/TULARC/society/calendars/2-5-What-day-of-the-week-was-2-August-1953.html
 
-# Note: for leap years, start date is assumed to be 1 AD.
-# counts the number of leap years up to January 1st of a given year.
-# Keep in mind that if specified year is a leap year, the leap day
-# has not happened before January 1st of that year.
-proc countLeapYears(yearSpan: int): int =
-  (((yearSpan - 1) / 4) - ((yearSpan - 1) / 100) + ((yearSpan - 1)/400)).int
-
-proc countDays(yearSpan: int): int =
+proc countLeapYears*(yearSpan: int): int =
+  ## Returns the number of leap years spanned by a given number of years.
+  ##
+  ## Note: for leap years, start date is assumed to be 1 AD.
+  ## counts the number of leap years up to January 1st of a given year.
+  ## Keep in mind that if specified year is a leap year, the leap day
+  ## has not happened before January 1st of that year.
+  (((yearSpan - 1) / 4) - ((yearSpan - 1) / 100) + ((yearSpan - 1) / 400)).int
+
+proc countDays*(yearSpan: int): int =
+  ## Returns the number of days spanned by a given number of years.
   (yearSpan - 1) * 365 + countLeapYears(yearSpan)
 
-proc countYears(daySpan: int): int =
-  # counts the number of years spanned by a given number of days.
+proc countYears*(daySpan: int): int =
+  ## Returns the number of years spanned by a given number of days.
   ((daySpan - countLeapYears(daySpan div 365)) div 365)
 
-proc countYearsAndDays(daySpan: int): tuple[years: int, days: int] =
-  # counts the number of years spanned by a given number of days and the remainder as days.
+proc countYearsAndDays*(daySpan: int): tuple[years: int, days: int] =
+  ## Returns the number of years spanned by a given number of days and the
+  ## remainder as days.
   let days = daySpan - countLeapYears(daySpan div 365)
   result.years = days div 365
   result.days = days mod 365