money icon indicating copy to clipboard operation
money copied to clipboard

Support for historical exchange rates

Open yinquanteo opened this issue 13 years ago • 7 comments

Hi,

It'll be nice if the exchange_to method in money/money.rb and the exchange_with method in money/bank/base.rb took an optional Date parameter (that defaults to Date.today).

I'm aware that there is a money-historical-bank gem which has a custom bank.exchange_with method. Do you think it is a good idea to include an optional Date parameter within the core money infrastructure so that we can make use of the methods there? (e.g. arithmetic)

For example,

a = "1 USD".to_money
b = "1 GBP".to_money
a.+(b, Date.yesterday)

instead of

a = "1 USD".to_money
b = "1 GBP".to_money
bank = Money::Bank::VariableExchange.new
# ... add exchange rates here
a + bank.exchange_with(Date.yesterday, b, "USD")

Do you have plans to support this feature? If not, and if you are supportive of adding it, I can look into it.

yinquanteo avatar Aug 06 '13 07:08 yinquanteo

Sounds cool but in my opinion as it's not really fundamental money functionality and probably only relevant for few projects, I'd say it sounds like sth. to go into a to-be-created money-ext gem or so.

marcoow avatar Aug 06 '13 08:08 marcoow

My opinion is similar to @marcoow's - if you are using this gem in production in real world (everything which is fiscal), the historical rates are often required. So making this as an extension is perfect compromise. For me big :+1:

matma avatar Aug 06 '13 08:08 matma

Since historical rates are often required, wouldn't it make sense to include it in the core infrastructure of the money gem?

The problem with creating a money extension gem is that a lot of the methods (such as in arithmetic) will have to be re-written with a lot of repetition. They'll have to be constantly re-synced whenever there is a new money gem release.

yinquanteo avatar Aug 06 '13 09:08 yinquanteo

Sorry, I somehow misread your original post - thought the proposal was to add the #exchange_with method to the money gem. I think adding an additional parameter to the + operator is not such a great idea actually as it's kind of a surprising syntax and not really necessary as it only saves a few lines...

I'd say it would be much better syntax if you e.g. had sth. like this (also with this solution there would be no duplication in a hypothetical money-ext gem):

a = "1 USD".to_money
b = "1 GBP".to_money
a + b.at(Date.yesterday, 'USD')

marcoow avatar Aug 06 '13 10:08 marcoow

I agree with @marcoow that his solution would be preferred. This should be an extension most definitely. I'd have not problem rolling it under the RubyMoney org though to make sure it gets love from the community.

semmons99 avatar Aug 06 '13 18:08 semmons99

@marcoow that's way better syntax! @semmons99 thanks. It'll probably make sense to patch the historical bank gem? I'll look into it.

yinquanteo avatar Aug 08 '13 05:08 yinquanteo

@yinquanteo yeah.

semmons99 avatar Aug 08 '13 11:08 semmons99