1
votes

I would like to add a %custom directive to strfime that will translate months to the code used in some financial/trading reports

  • January => F
  • February => G
  • March => H
  • April => J
  • May => K
  • June => M
  • July => N
  • August => Q
  • September => U
  • October => V
  • November => X
  • December => Z

I've tried finding documentation on this but was not able to find. Any ideas? Thanks in advance!

1

1 Answers

2
votes

Directives are hardcoded in strftime.c and cannot be extended.

Maybe try this?

months = { "Jan" => "F", "Feb" => "G", ... }
Date.today.strftime('%b %d, %Y').gsub(Regexp.union(months.keys), months)
# => "F 08, 2017"