Skip to content
Ruby Gem to convert DateTime to DTG
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build Status Coverage Status Maintainability Test Coverage Inline docs

Gem Version Downloads Download Rank Daily Download Rank Yard Documentation

License GitHub version Open Github Issues Closed Github Issues

Star Project Watch Project Follow Me


DTG is a ruby gem to convert Time objects into DTG format.

A DTG is a DateTimeGroup which is used in the military to save time. DTG are saved in the format DDHHMML MMM YY, where D is day, H is hour, L is letter, M is month, and Y is year. The Month is the 3 character representation such as JAN for January, MAY for May, DEC for December and so on. Year is only the last two digits of the year e.g. 2019 is just 19. The letter is the zone code such as W for whiskey which is HST, Z for zulu which is GMT, A-Z are the zones used.

DTG integrates natively with the DateTime, Time, and ActiveSupport::TimeWithZone classes in Ruby/Rails and is callable on all Time objects. DTG returns a visually formatted dtg converted based on knolwedge of the zone of the object and the intended zone. It is also respective of daylight savings time of your objects zone and its intended zone.

DTG is the military acronym referring to what is also called nautical or maritime time zones. These zones are mapped across the world from A-Z not including J as J references the local timezone of yourself.

Table of Contents

  1. DTG
  2. Table of Contents
  3. Usage
    1. DTG Zones
    2. DTG Zone Map
  4. Installation
  5. Testing
  6. Compatability
  7. Problems
  8. Contributing
  9. License


DTG implements the method to_dtg into the Time class and is fully compatible with all Time objects(DateTime, Time, and TimeWithZone have been tested, custom objects should also function the same as long as their properties emulate that of the former).

To use:


and it will return the time object as a string in the zulu timezone in dtg format.

For other DTG formats:


where zone is any single letter symbol A-Z, capital or lower case and it will return the time object as a string in the zone format.

USAGE NOTES: Ensure that in your application or before using this gems methods(convert/to_dtg) which calls the in_time_zone method, you must set = "yourtimezone(HST for me)". Otherwise in_time_zone will be called and return nil:NilObject due to returning nil(ActiveSupport thing). Rails has a place in the application configuration to set the before startup.

DTG Zones

  • A: Alpha Time: UTC +01:00 (Paris, France)
  • B: Bravo Time: UTC +02:00 (Athens, Greece)
  • C: Charlie Time: UTC +03:00 (Moscow, Russia)
  • D: Delta Time: UTC +04:00 (Kabul, Afghanistan)
  • E: Echo Time: UTC +05:00 (New Delhi, India)
  • F: Foxtrot Time: UTC +06:00 (Dhanka, Bangladesh)
  • G: Golf Time: UTC +07:00 (Bangkok, Thailand)
  • H: Hotel Time: UTC +08:00 (Beijing, China)
  • I: India Time: UTC +09:00 (Tokyo, Japan)
  • J: Juliet Time: (Local Time Zone)
  • K: Kilo Time: UTC +10:00 (Sydney, Australia)
  • L: Lima Time: UTC +11:00 (Honiara, Solomon Islands)
  • M: Mike Time: UTC +12:00 (Wellington, New Zealand)
  • N: November Time: UTC -01:00 (Azores)
  • O: Oscar Time: UTC -02:00 (Gothab, Greenland)
  • P: Papa Time: UTC -03:00 (Buenos Aires, Argentina)
  • Q: Quebec Time: UTC -04:00 (Halifax, Nova Scotia)
  • R: Romeo Time: UTC -05:00 (New York, NY United States)
  • S: Sierra Time: UTC -06:00 (Dallas, TX United States)
  • T: Tango Time: UTC -07:00 (Denver, CO United States)
  • U: Uniform Time: UTC -08:00 (Los Angeles, CA United States)
  • V: Victor Time: UTC -09:00 (Juneau, AK United States)
  • W: Whiskey Time: UTC -10:00 (Honolulu, HI United States)
  • X: X-Ray Time: UTC -11:00 (Nome, AK United States)
  • Y: Yankee Time: UTC -12:00 (Suva, Fiji)
  • Z: Zulu Time: UTC +-00:00 (Greenwich, England)

DTG Zone Map

DTG zones displayed across the map with their offsets


Add this line to your application's Gemfile:

gem 'dtg'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dtg


If you would like to test this gem before adding it to your project to see it's functionality, follow these steps:

  1. Clone the repository
git clone
  1. cd into the test/dummy directory

  2. Start the rails console

rails console


rails c
  1. Test away
#<Tested in irb console(default rails), also works in Pry console>

y =
y =

x =

z =
z.convert :w
z.to_dtg :c :Q L.to_sym

Note: The .dtg method will return a string naming the type of the object you called it on and can therefore be used to verify if the gem has successfully natively integrated with Ruby/Rails(should fail if not). I included this for testing purposes to check that the right modules were being loaded with DTG and have run into no load failures but for peace of mind I left it in in case you want to see for yourself.


All versions of DTG are 100% compatible with all versions of rails so long as date(DateTime) time(Time) and TimeWithZone(ActiveSupport::TimeWithZone) are present otherwise the features associated with those classes will not be available. The gem will still function without them as I have discovered through and the features associated with the missing classes will just not be there, however, attempting to use the features with one of the non-existant classes it integrates into will most likely error or cause strange behaviours so I recommend only using with the classes your application contains(i.e. do not attempt to use ActiveSupport::TimeWithZone with pure ruby unless you include it somehow in your application), luckily, all rails applications contain all 3 classes and any ruby application contains Time by default and as of lately, also contains date(I think) although the TimeWithZone will most likely not be there since it is from activesupport which is part of the rails gem.

This Gem now includes the necessary libraries from active_support and date to work without rails. It is 100% compatible with all versions of rails/active_support. If you do not set to a valid zone(many ways to do this, I recommend the 3 char code such as HST for Hawaiian Standard Time when you set your timezone to ensure proper zone coverage if your zone does daylight savings time or summer time. DateTimeGroup#convert and DateTimeGroup#to_dtg(which calls convert) will result in nil:NilObject if is not set before using them. Works with irb/pry/ruby/rails and probably more that I haven't tested yet. Enjoy!


DTG relies upon time objects that have timezone set either as or as the default offset recorded. I recommend setting the application timezone in the application.rb configuration file so that dtg works automatically on any generated time objects otherwise it will convert all time objects from UTC +00:00 which is the rails default zone (Etc/UTC) and therefore can provide unintended results. TimeWithZone is different and therefore is a Time with offset and with zone. Therefore without data loss, you can convert from TimeWithZone to DateTime or Time and maintain the same time, however, you may lose the zone code but the offset will be kept and the zone code can be recovered based on this offset but certain zones that follow daylight savings time may lose their savings-ness and will no longer spring forward or backward if converted.


If you want to contribute please let me know though either an email or you can just submit a pull request to add anything!


The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.