Dates have no range checking which makes parsing them slightly
unreliable and causes weird error messages like this:
```
> #25:00#
Most likely pattern `hour12:min[:sec] meridiem[ offset]` failed: Expected ` `, got eof
```
Additionally, large numbers cause a panic:
```
> #9999999999#
Panic: The application panicked (crashed).
Message: called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
Location: core/src/parsing/datetime.rs:117
Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
```
This PR adds range checks. I also cleaned up the code a little.
Fixes "4 bytes -> GB" being an error saying you can't convert to a
timezone.
This timezone can be obtained in better ways, there's no reason it
should be like this.
I want rink to adhere slightly better to conventions on Linux.
- Adds man pages for the CLI and for the config file format, using
asciidoc.
- Updates the bundling functionality. It doesn't make sense to bundle
these files when building a distro package, they should go in
`/usr/share`.
- Adds a makefile with good defaults for distro packages.
The asciidoc files will likely become the new source of truth for rink's
documentation. There is no way to make PRs to github wikis, so this
might be for the best anyway.
Currently rink is packaged on arch, nix, and void linux.
## Changes to `definitions.units`
- Added vim folds repurposing the `!category`/`!endcategory` syntax. There's a modeline at the bottom of the file for this.
- To make the vim folds work better, every single unit now has a category. I also moved them around a little bit so that each category collapses to a single line. This makes the file much easier to navigate. Kind of acts as its own table of contents.
- Rearranged some of the categories, and moved things between categories.
- Adjusted several comments, and added an explanation of the file to the top.
- Deleted some legacy GNU Units directives like !utf8 that Rink will never use. Also several of the function/LUTs that are commented out.
- Uncommented some fractions that apparently GNU Units didn't like. Also uncommented `googol`.
- Moved mercury to the periodic table section.
- Moved the 4 newest elements to be alphabetically sorted.
- Added atomic numbers to every element. (I double checked that the numbers are correct, but I might have still gotten some mixed up...)
- Fixed a few typos and trailing whitespace.
![image](https://github.com/tiffany352/rink-rs/assets/1254344/3d3fbc58-1928-4ded-8612-a84778127c65)
## Changes to rink-core
- Now prints an error on unrecognized directives instead of silently ignoring them.
- Ignores categories for non-units. This may be re-added later but it will require refactoring `Context::categories` to respect namespaces.
- Improved some of the error messages from the units DB loader.
ECB doesn't include HRK anymore because of it being pinned now, now the message will be correct for older versions of Rink.
Also updated the fallback values since they're 2 years old.
Croatia adopted the euro on 2023-01-01, setting a fixed conversion rate of the kuna to euro to 7.53450 kuna per 1 euro. https://www.ecb.europa.eu/euro/changeover/croatia/html/index.en.html
The kuna is still often listed and used as a reference, so not removing it, but instead setting a fixed conversion rate and adding a couple of often used slang names for varied amounts.
Makes quantities occupy a different namespace from units. This means you can no longer write them in expressions as though they were units, which was confusing.
Fixes#12, which is one of the longest standing bugs in Rink.
Yet another giant refactor PR. I'm trying to clean up the Context internals. I moved a lot of the fields into a new Registry object with the hopes of making future refactors to it easier.
A lot of things are poorly named, and I've been going through and updating those. Some of these fields I didn't even know what they did until I studied them carefully, since I'd forgotten over time.
This makes some breaking changes to the Defs serialization format, but I didn't touch Unit or Substance which are the only ones that are used by the backend currently.
Some other refactors I did:
- Updated quantities to no longer reference units, only base units and other quantities.
- Added a debug dump option to the CLI for showing the contents of the Context.
- Merged Def::BaseUnit & Canonicalization.
- Merged Def::Prefix & SPrefix. I don't actually know what SPrefix stood for originally (standalone? definitely not short).
- Prefixes are now required to be dimensionless.
- Added missing tests for the Def serialization format.
I'm not entirely done yet though. There's still one dependency on Context from the loader, which is on the eval() method, used by units and substances. I'm still thinking about how I can reduce that coupling.
Much of the code organization and architecture of Rink has been the same since I hacked this project together in 2016. In this PR, I spent about a day moving files around and refactoring code.
I'm hoping that cleaning up the codebase like this will help make it easier to change going forwards. There's a lot of duplicated code, few abstractions are used.
In order to make this not break everything I did it in tiny steps, verifying the test suite each time. The original branch has >30 commits in it as a result.
Most users probably want to manipulate time relative to the present in
their local timezone. This brings rink's functionality closer to similar
tools.
In date(1):
> date -d 'now + 1 hour'
Fri 23 Jul 09:54:02 CEST 2021
Before:
> now
2021-07-23 06:54:05.699222874 +00:00 (now)
> now + 1 hour
2021-07-23 07:54:10.940110380 +00:00 (in an hour)
After:
> now
2021-07-23 08:54:13.219044877 +02:00 (now)
> now + 1 hour
2021-07-23 09:54:15.555096329 +02:00 (in an hour)