Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format currency amounts in fare_products.txt with 2 decimal digits #320

Merged
merged 4 commits into from
Jan 10, 2025

Conversation

sberkley
Copy link
Contributor

@sberkley sberkley commented Jan 9, 2025

Summary:

Currently, these modules will incorrectly convert FareProduct amounts to output with an incorrect number of decimal places. For example, "2.50" will be converted to "2.5" when using the transformer or merger CLI. This results in the validation error https://gtfs-validator.mobilitydata.org/rules.html#invalid_currency_amount-rule.

This PR fixes the issue by treating the value as a Java Currency object, then using the CurrencyInstance of DecimalFormatter (stripped of the currency symbol) that produces a string format with the correct number of decimal places based on the currency.

Expected behavior:

  • Tests in FareAmountFieldMappingFactoryTest will pass
  • Output to the amount field in fare_products.txt will include 0 or 2 decimal places, depending on currency specified. It will "correct" the input as long as it can successfully parse as a decimal number.
  • Datasets processed with onebusaway-gtfs-transformer-cli, onebusaway-gtfs-merge-cli, or other tools that use onebusaway-gtfs will no longer generate output that results in the https://gtfs-validator.mobilitydata.org/rules.html#invalid_currency_amount-rule ERROR.

When exporting to CSV, FareProduct amount should use the appropriate number of decimal places based on the currency specified. Introduces FareAmountFieldMappingFactory to do so.
explicitly cast fare amount from CSV to string, then float
use string in CSV to object tests
@leonardehrenfried leonardehrenfried changed the title Currency format Format currency amounts in fare_products.txt with 2 decimal digits Jan 10, 2025
@leonardehrenfried leonardehrenfried merged commit 8eb7f39 into OneBusAway:master Jan 10, 2025
5 checks passed
@leonardehrenfried
Copy link
Collaborator

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants