浏览代码

Use tropical years as 'year' unit

We follow GNU units and Frink here and use the mean tropical year
for the `year` unit. See `numbat/modules/units/time.nbt` for details.

The Gregorian year is still available as `gregorian_year`.

closes #321
David Peter 1 年之前
父节点
当前提交
d43737c1e6
共有 4 个文件被更改,包括 36 次插入11 次删除
  1. 2 1
      book/src/list-units.md
  2. 3 3
      examples/consistency_others.nbt
  3. 1 1
      examples/workhours.nbt
  4. 30 6
      numbat/modules/units/time.nbt

+ 2 - 1
book/src/list-units.md

@@ -171,6 +171,7 @@ and — where sensible — units allow for [binary prefixes](https://en.wikipedi
 | `Time` | [Day](https://en.wikipedia.org/wiki/Day) | `d`, `day`, `days` |
 | `Time` | [Decade](https://en.wikipedia.org/wiki/Decade) | `decade`, `decades` |
 | `Time` | [Fortnight](https://en.wikipedia.org/wiki/Fortnight) | `fortnight`, `fortnights` |
+| `Time` | [Gregorian year](https://en.wikipedia.org/wiki/Gregorian_year) | `gregorian_year`, `gregorian_years` |
 | `Time` | [Hour](https://en.wikipedia.org/wiki/Hour) | `h`, `hour`, `hours`, `hr` |
 | `Time` | [Julian year](https://en.wikipedia.org/wiki/Julian_year_(astronomy)) | `julian_year`, `julian_years` |
 | `Time` | [Millennium](https://en.wikipedia.org/wiki/Millennium) | `millennia`, `millennium` |
@@ -181,7 +182,7 @@ and — where sensible — units allow for [binary prefixes](https://en.wikipedi
 | `Time` | [Sidereal day](https://en.wikipedia.org/wiki/Sidereal_time#Sidereal_day) | `sidereal_day`, `sidereal_days` |
 | `Time` | [Stoney time](https://en.wikipedia.org/wiki/Stoney_units) | `stoney_time` |
 | `Time` | [Week](https://en.wikipedia.org/wiki/Week) | `week`, `weeks` |
-| `Time` | [Gregorian year](https://en.wikipedia.org/wiki/Gregorian_year) | `year`, `years`, `yr` |
+| `Time` | [Tropical year](https://en.wikipedia.org/wiki/Tropical_year) | `tropical_year`, `tropical_years`, `year`, `years`, `yr` |
 | `Velocity` | [Knot](https://en.wikipedia.org/wiki/Knot_(unit)) | `kn`, `knot`, `knots`, `kt` |
 | `Velocity` | [Kilometres per hour](https://en.wikipedia.org/wiki/Kilometres_per_hour) | `kph` |
 | `Velocity` | [Miles per hour](https://en.wikipedia.org/wiki/Miles_per_hour) | `mph` |

+ 3 - 3
examples/consistency_others.nbt

@@ -12,10 +12,10 @@ assert_eq(1 min, 60 s)
 assert_eq(1 hour, 60 min)
 assert_eq(1 week, 7 day)
 assert_eq(1 day, 24 hour)
-assert_eq(1 month, 730.485 hour)
-assert_eq(1 year, 365.2425 day)
-assert_eq(1 year, 12 months)
+assert_eq(1 month, 730.485 hour, 0.001 hour)
+assert_eq(1 gregorian_year, 365.2425 day)
 assert_eq(1 julian_year, 365.25 day)
+assert_eq(1 year, 1 tropical_year)
 
 assert_eq(1 gallon, 231 inch³, 1e-5 inch³)
 assert_eq(8 pint, 1 gallon)

+ 1 - 1
examples/workhours.nbt

@@ -21,4 +21,4 @@ let duration = 0.5 year
 print(3 FTE * 0.5 years -> workdays)
 print(budget / rate / duration -> FTE)
 assert_eq(3 FTE * 0.5 years -> workdays, 300 workday)
-assert_eq(budget / rate / duration -> FTE, 5 FTE)
+assert_eq(budget / rate / duration -> FTE, 5 FTE, 1e-6 FTE)

+ 30 - 6
numbat/modules/units/time.nbt

@@ -1,23 +1,47 @@
 use units::si
 
-### Time units
-
 @name("Week")
 @url("https://en.wikipedia.org/wiki/Week")
 @aliases(weeks)
 unit week: Time = 7 days
 
-@name("Gregorian year")
-@url("https://en.wikipedia.org/wiki/Gregorian_year")
+# The mean tropical year changes over time (half a second per century). It's current
+# value can be approximated using
+#
+#   365.2421896698 - 6.15359e-6 T - 7.29e-10 T^2 + 2.64e-10 T^3
+#
+# where T is in Julian centuries, measured from noon January 1st, 2000.
+# (https://en.wikipedia.org/wiki/Tropical_year#Mean_tropical_year_current_value)
+#
+# Values of the mean tropical year for the recent past and near future:
+#
+#   Year    Length (days)
+#   ---------------------
+#   2020    365.242 189 7
+#   2025    365.242 188 1
+#   2050    365.242 186 6
+#
+# For now, we use the 2025 value as a hardcoded constant. Those numbers
+# are mainly shown to illustrate that it is not sensible to define this
+# number more precise.
+#
+@name("Tropical year")
+@url("https://en.wikipedia.org/wiki/Tropical_year")
 @metric_prefixes
-@aliases(years, yr: short)
-unit year: Time = 365.2425 days
+@aliases(years, yr: short, tropical_year, tropical_years)
+unit year: Time = 365.242_188_1 days
 
 @name("Month")
 @url("https://en.wikipedia.org/wiki/Month")
 @aliases(months)
 unit month: Time = year / 12
 
+@name("Gregorian year")
+@url("https://en.wikipedia.org/wiki/Gregorian_year")
+@metric_prefixes
+@aliases(gregorian_years)
+unit gregorian_year: Time = 365.2425 days
+
 @name("Julian year")
 @url("https://en.wikipedia.org/wiki/Julian_year_(astronomy)")
 @aliases(julian_years)