Miti
Converts between English (AD) and Nepali (BS) dates. Includes a CLI app, Rails helpers (date picker, calendar, model concern), and full Rails integration.
Installation
$ gem install miti
Or add to your Gemfile:
$ bundle add miti
CLI
All date arguments must be in YYYY-MM-DD or YYYY/MM/DD format.
$ miti today
# [2082-01-15 BS] Baisakh 15, 2082 Wednesday
# [2025-04-28 AD] April 28, 2025 Monday
$ miti to_bs 2025-04-28
# [2082-01-15 BS] Baisakh 15, 2082 Wednesday
$ miti to_ad 2082-01-15
# [2025-04-28 AD] April 28, 2025 Monday
$ miti next
# 17 days left until 1st Jestha
# Current month's last date => 31 Baisakh
Ruby API
require "miti"
Miti.to_bs("2025-04-28")
#=> #<Miti::NepaliDate:0x... @barsa=2082, @mahina=1, @gatey=15>
Miti.to_bs("2025-04-28").descriptive
#=> "Baisakh 15, 2082 Wednesday"
Miti.to_bs("2025-04-28").descriptive(nepali: true)
#=> "बैशाख 15, 2082 Wednesday(बुधबार)"
Miti.to_bs("2025-04-28").to_s
#=> "2082-01-15"
Miti.to_bs("2025-04-28").format("%g %b %m")
#=> "15 2082 01"
Miti.to_bs("2025-04-28").format("%B %g, %Y %A")
#=> "Baisakh 15, 2082 Wednesday"
Miti.to_bs("2025-04-28").format("%B %g, %Y %A", nepali: true)
#=> "बैशाख 15, 2082 बुधबार"
Miti.to_ad("2082-01-15")
#=> #<Date: 2025-04-28 ...>Rails Integration
Setup
$ rails generate miti:install
To copy styles into your app for customization:
$ rails generate miti:install --copy-styles
To undo: rails destroy miti:install
Date picker (popover calendar)
<%= form.nepali_date_field :happened_on %>
<!-- readonly text input with calendar icon that opens a month/year picker popover -->
<!-- submits as event[happened_on] — no _bs suffix needed -->With a default value:
<%= form.nepali_date_field :happened_on, value: "2082-01-15" %>Themes
<%= form.nepali_date_field :happened_on, theme: :dark %>
<%= form.nepali_date_field :happened_on, theme: :tokyo_night %>Available themes: light (default), dark, indigo, midnight, tokyo_night, nord.
Use data-miti-theme on any ancestor to style a group of pickers:
<div data-miti-theme="dark">
<%= form.nepali_date_field :start_date %>
<%= form.nepali_date_field :end_date %>
</div>Dark mode auto-detects prefers-color-scheme: dark. Set data-miti-theme-auto="false" on any ancestor to disable:
<div data-miti-theme-auto="false">
<%= form.nepali_date_field :happened_on %>
</div>Date range picker
<%= form.nepali_date_range_field :start_date, :end_date %>
<!-- Single clickable input + two hidden inputs; drag-to-select or click-to-select range -->With defaults:
<%= form.nepali_date_range_field :start_date, :end_date,
start_value: "2082-01-15", end_value: "2082-02-10" %>Without a form builder:
<%= nepali_date_range_field :event, :start_date, :end_date %>The display shows a friendly range like "Baisakh 15 – Jestha 3, 2082". Opens a single popover with drag-to-select. Fires miti:range-selected custom event on selection.
Options: theme, start_value, end_value, trigger_html.
Date select (3 dropdowns)
<%= form.nepali_date_select :happened_on %>
<!-- renders year, month, day select elements -->Model concern
class Event < ApplicationRecord
include Miti::Rails::ModelConcern
has_nepali_date :happened_on
endThis defines:
-
event.happened_on_bs— returns BS date asMiti::NepaliDate -
event.happened_on_bs = "2082-01-15"— sets the AD column from a BS string -
event.happened_on_bs_human— readable description (respectsI18n.locale) -
event.happened_on = "2083-01-15"— auto-converts BS string to AD via custom type
Optional BS column storage
class Event < ApplicationRecord
include Miti::Rails::ModelConcern
has_nepali_date :happened_on, store_bs: true
endThe setter writes the BS string to the happened_on_bs column on assignment. Generate the migration:
$ rails generate miti:store_bs Event happened_on
With store_bs: true:
-
event.happened_on_bsreads from the DB column directly (zero conversion cost) - Falls back to converting from AD if the column is empty
- The setter writes the BS string to the column immediately
Calendar grid
<%= nepali_calendar(year: 2082, month: 1) do |day| %>
<%= day.gatey %>
<% end %>Renders a monthly grid with Turbo Frame navigation.
Agenda view
<%= nepali_calendar_agenda(start_date, end_date, group_by: :week) do |day| %>
<%= day.descriptive %>
<% end %>Renders a grouped list of dates.
DayPresenter
Yielded to calendar/agenda blocks:
| Method | Returns |
|---|---|
day.gatey |
Day of month (1-32) |
day.barsa |
Year |
day.mahina |
Month (1-12) |
day.bar |
Weekday index (0=Sunday) |
day.tarik |
Equivalent AD Date
|
day.to_s |
BS date as yyyy-mm-dd
|
day.descriptive |
Human readable |
day.today? / day.sunday? / day.saturday?
|
Boolean checks |
Ruby version
Supports Ruby 3.1 through 4.x. Rails integration loads automatically when Rails is defined.
Development
$ bin/setup
$ bundle exec rake spec
$ bin/console
Contributing
Bug reports and pull requests are welcome at github.com/xkshitizx/miti.
License
The gem is available as open source under the terms of the MIT License.