   ordinalizeToken = (func, period) ->
     (a) -> @lang().ordinal func.call(this, a), period
 
-  do ->
+  do -> # Needed to make `i` a cal variable
     while ordinalizeTokens.length
       i = ordinalizeTokens.pop()
       formatTokenFunctions['j' + i + 'o'] =

      k += 1 if leap is 1
    jm = 7 + div(k, 30)
    jd = mod(k, 30) + 1
    return jy: jy, jm: jm, jd: jd

  # Calculates the Julian Day number from Gregorian or Julian
  # calendar dates. This integer number corresponds to the noon of
  # the date (i.e. 12 hours of Universal Time).
  # The procedure was tested to be good since 1 March, -100100 (of both
  # calendars) up to a few million years into the future.
  #
  # @param gy Calendar year (years BC numbered 0, -1, -2, ...)
  # @param gm Calendar month (1 to 12)
  # @param gd Calendar day of the month (1 to 28/29/30/31)
  # @return Julian Day number
  g2d = (gy, gm, gd) ->
    d = div((gy + div(gm - 8, 6) + 100100) * 1461, 4) +
        div(153 * mod(gm + 9, 12) + 2, 5) + gd - 34840408
    d = d - div(div(gy + 100100 + div(gm - 8, 6), 100) * 3, 4) + 752
    d

  # Calculates Gregorian and Julian calendar dates from the Julian Day number
  # (jdn) for the period since jdn=-34839655 (i.e. the year -100100 of both
  # calendars) to some millions years ahead of the present.
  #
  # @param jdn Julian Day number
  # @return
  #   gy: Calendar year (years BC numbered 0, -1, -2, ...)
  #   gm: Calendar month (1 to 12)
  #   gd: Calendar day of the month M (1 to 28/29/30/31)
  d2g = (jdn) ->
    j = 4 * jdn + 139361631
    j = j + div(div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908

    toJalaali: toJalaali
    toGregorian: toGregorian

  ###
    Helper functions used in conversion.
  ###
  div = (a, b) -> ~~(a / b)
  mod = (a, b) -> a - ~~(a / b) * b

  ###
    This function determines if the Jalaali (Persian) year is
    leap (366-day long) or is the common year (365 days), and
    finds the day in March (Gregorian calendar) of the first
    day of the Jalaali year (jy).

    @param jy Jalaali calendar year (-61 to 3177)
    @return
      leap: number of years since the last leap year (0 to 4)
      gy: Gregorian year of the beginning of Jalaali year
      march: the March day of Farvardin the 1st (1st day of jy)
    @see: http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm
    @see: http://www.fourmilab.ch/documents/calendar/
  ###
  jalCal = (jy) ->
    # Jalaali years starting the 33-year rule.
    breaks = [
