Sha256: e91fa310c00dd1e19b34c000df466d5039c304768e3b04e6b1e8e6236b2abeb9

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

class TwitterCldr.Calendar
  REDIRECT_PREFIX = "calendars.gregorian."

  @calendar: `{{{calendar}}}`

  @months: (options = {}) ->
    root = @get_root("months", options)
    result = []
    result[parseInt(key) - 1] = val for key, val of root
    result

  @weekdays: (options = {}) ->
    @get_root("days", options)

  @quarters: (options = {}) ->
    @get_root("quarters", options)

  @periods: (options = {}) ->
    @get_root("periods", options)

  @get_root: (key, options = {}) ->
    root = @calendar[key]
    names_form = options["names_form"] || "wide"

    format = options.format || if root?["stand-alone"]?[names_form]?
      "stand-alone"
    else
      "format"

    data = root[format][names_form]

    # handle redirects, e.g., { "days": { "stand-alone": { "wide": "calendars.gregorian.days.format.wide" } } }
    if typeof data is "string" and data.indexOf(REDIRECT_PREFIX) == 0
      [key, format, names_form] = data.slice(REDIRECT_PREFIX.length).split(".")
      @calendar[key]?[format]?[names_form] || throw "invalid redirect #{data}"
    else
      data

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twitter_cldr_js-2.4.0 lib/twitter_cldr/js/mustache/shared/calendar.coffee
twitter_cldr_js-2.3.2 lib/twitter_cldr/js/mustache/shared/calendar.coffee