Sha256: 36f220a5e5716a7eab5e98eb75f22f3fcb15db4300ad5e296efa34b91bef15ee

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

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

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

  @calendar: ->
    TwitterCldr.get_data()[@name].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

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr_js-3.1.0 lib/twitter_cldr/js/mustache/implementation/shared/calendar.coffee