Path: blob/trunk/third_party/closure/goog/date/relativewithplurals.js
2868 views
// Copyright 2009 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Code to make goog.date.relative plurals-aware.16*/1718goog.provide('goog.date.relativeWithPlurals');1920goog.require('goog.date.relative');21goog.require('goog.date.relative.Unit');22goog.require('goog.i18n.MessageFormat');232425/**26* Gets a localized relative date string for a given delta and unit.27* @param {number} delta Number of minutes/hours/days.28* @param {boolean} future Whether the delta is in the future.29* @param {goog.date.relative.Unit} unit The units the delta is in.30* @return {string} The message.31* @private32*/33goog.date.relativeWithPlurals.formatTimeDelta_ = function(delta, future, unit) {34if (!future && unit == goog.date.relative.Unit.MINUTES) {35/**36* @desc Relative date indicating how many minutes ago something happened.37*/38var MSG_MINUTES_AGO_ICU = goog.getMsg(39'{NUM, plural, ' +40'=0 {# minutes ago}' +41'=1 {# minute ago}' +42'other {# minutes ago}}');4344return new goog.i18n.MessageFormat(MSG_MINUTES_AGO_ICU).format({45'NUM': delta46});4748} else if (future && unit == goog.date.relative.Unit.MINUTES) {49/**50* @desc Relative date indicating in how many minutes something happens.51*/52var MSG_IN_MINUTES_ICU = goog.getMsg(53'{NUM, plural, ' +54'=0 {in # minutes}' +55'=1 {in # minute}' +56'other {in # minutes}}');5758return new goog.i18n.MessageFormat(MSG_IN_MINUTES_ICU).format({59'NUM': delta60});6162} else if (!future && unit == goog.date.relative.Unit.HOURS) {63/**64* @desc Relative date indicating how many hours ago something happened.65*/66var MSG_HOURS_AGO_ICU = goog.getMsg(67'{NUM, plural, ' +68'=0 {# hours ago}' +69'=1 {# hour ago}' +70'other {# hours ago}}');7172return new goog.i18n.MessageFormat(MSG_HOURS_AGO_ICU).format({73'NUM': delta74});7576} else if (future && unit == goog.date.relative.Unit.HOURS) {77/**78* @desc Relative date indicating in how many hours something happens.79*/80var MSG_IN_HOURS_ICU = goog.getMsg(81'{NUM, plural, ' +82'=0 {in # hours}' +83'=1 {in # hour}' +84'other {in # hours}}');8586return new goog.i18n.MessageFormat(MSG_IN_HOURS_ICU).format({'NUM': delta});8788} else if (!future && unit == goog.date.relative.Unit.DAYS) {89/**90* @desc Relative date indicating how many days ago something happened.91*/92var MSG_DAYS_AGO_ICU = goog.getMsg(93'{NUM, plural, ' +94'=0 {# days ago}' +95'=1 {# day ago}' +96'other {# days ago}}');9798return new goog.i18n.MessageFormat(MSG_DAYS_AGO_ICU).format({'NUM': delta});99100} else if (future && unit == goog.date.relative.Unit.DAYS) {101/**102* @desc Relative date indicating in how many days something happens.103*/104var MSG_IN_DAYS_ICU = goog.getMsg(105'{NUM, plural, ' +106'=0 {in # days}' +107'=1 {in # day}' +108'other {in # days}}');109110return new goog.i18n.MessageFormat(MSG_IN_DAYS_ICU).format({'NUM': delta});111112} else {113return '';114}115};116117goog.date.relative.setTimeDeltaFormatter(118goog.date.relativeWithPlurals.formatTimeDelta_);119120121