node package manager

worldtime

Convert to and from various worldtime formats. Get manipulated time values.

worldtime

(c)Bumblehead, 2013,2014,2015,2016 MIT-license

worldtime uses official Unicode ldml-JSON files to format and parse international times (files are found in json-locale).

worldtime extends simpletime to provide all simpletime methods. Use it to format and unformat international time using unicode forms.

var worldtime = require('worldtime'),
    uobj = require('es_CL.json');
 
worldtime.getFormattedDate(uobj, new Date(), 'medium');
// "09-01-2016" 
 
worldtime.extractFormattedDate(uobj, '09-01-2016', 'medium');
// Sat Jan 09 2016 01:01:12 GMT-0800 (PST) 
 
worldtime.getDateMonthNameWide(uobj, new Date());
// "enero" 
 
worldtime.getNumericMonthNameWide(uobj, '2');
// "febrero" 
 
worldtime.getStrDayNameAbbrev(uobj, 'thu');
// "jue" 

The below method list is abbreviated. See worldtime and simpletime source files for the full list.


  • getCalendarObj ( uObj, calendarType )

    returns a calendar object from the unicode object. valid calendarTypes: "buddhist", "chinese", "coptic", "dangi", "ethiopic", "ethiopicAmeteAlem", "gregorian", "hebrew", "indian", "islamic", "islamicCivil", "japanese", "persian", "roc".

    ex,

    worldtime.getCalendarObj(uobj, 'gregorian').months.format.wide
    //{ '1': 'enero', 
    //  '2': 'febrero', 
    //  '3': 'marzo', 
    //  '4': 'abril', 
    //  '5': 'mayo', 
    //  '6': 'junio', 
    //  '7': 'julio', 
    //  '8': 'agosto', 
    //  '9': 'septiembre', 
    //  '10': 'octubre', 
    //  '11': 'noviembre', 
    //  '12': 'diciembre' } 
  • getCalendarUnit ( uObj, unitType )

    returns a calendar unit object from the unicode object. valid unitTypes: "months", "days", "quarters", "eras", "dateFormats", "timeFormats", "dateTimeFormats", "fields".

    ex,

    worldtime.getCalendarUnit(uobj, 'dateFormats').medium.dateFormat.pattern
    // 'dd-MM-yyyy' 
  • getMonthNameFormatObj ( uObj, monthType )

    returns an object of month names for the given month type. months are provided by the gregorian calendar object. valid monthTypes: "abbreviated", "narrow", "wide".

    ex,

    worldtime.getMonthNameFormatObj(uobj, 'abbreviated');
    //{ '1': 'ene', 
    //  '2': 'feb', 
    //  '3': 'mar', 
    //  '4': 'abr', 
    //  '5': 'may', 
    //  '6': 'jun', 
    //  '7': 'jul', 
    //  '8': 'ago', 
    //  '9': 'sep', 
    //  '10': 'oct', 
    //  '11': 'nov', 
    //  '12': 'dic' } 
  • getBaseMonthsArr ( uObj, formatType )

    returns an array of months for the given format type. valid formatType: "abbreviated", "narrow", "wide".

    ex,

    worldtime.getBaseMonthsArr(es_CLObj, 'abbreviated');
    //[ 'feb', 
    //  'mar', 
    //  'abr', 
    //  'may', 
    //  'jun', 
    //  'jul', 
    //  'ago', 
    //  'sep', 
    //  'oct', 
    //  'nov', 
    //  'dic' ] 
  • getNumericMonthNameAbbrev ( uObj, monthNum )

    returns a month name of the abbreviated month type for the given monthNum.

    ex,

    worldtime.getNumericMonthNameAbbrev(uobj, '1');
    // ene 
  • getNumericMonthNameWide ( uObj, monthNum )

    returns a month name of the wide month type for the given monthNum.

    ex,

    worldtime.getNumericMonthNameWide(uobj, '1');
    // enero 
  • getDayNameFormatObj ( uObj, dayType )

    returns an object of day names for the given day type. months are provided by the gregorian calendar object. valid dayType: "abbreviated", "narrow", "wide".

    ex,

    var result = worldtime.getDayNameFormatObj(uobj, 'abbreviated');
    //{ 'sun': 'dom', 
    //  'mon': 'lun', 
    //  'tue': 'mar', 
    //  'wed': 'mié', 
    //  'thu': 'jue', 
    //  'fri': 'vie', 
    //  'sat': 'sáb' } 
  • getBaseDaysArr ( uobj, formatType )

    returns an array of days for the given format type. valid formatType: "abbreviated", "narrow", "wide".

    ex,

    worldtime.getBaseDaysArr(uobj, 'abbreviated');
    //[ 'dom', 
    //  'lun', 
    //  'mar', 
    //  'mié', 
    //  'jue', 
    //  'vie', 
    //  'sáb' ] 
  • getStrDayNameAbbrev ( uObj, dayStr )

    returns a day name of the abbreviated day type for the given dayStr. valid dayStr: "sun", "mon", "tue", "wed", "thu", "fri", "sat".

    ex,

    worldtime.getStrDayNameAbbrev(uobj, 'mon');
    // lun 
  • getStrDayNameWide ( uObj, dayStr )

    returns a day name of the wide day type for the given dayStr.

    ex,

    worldtime.getStrDayNameWide(uobj, 'mon');
    // lunes 
  • getDateMonthNameAbbrev ( uObj, date )

    returns a "abbrev" day name for the given date.

    ex,

    worldtime.getDateMonthNameAbbrev(uobj, date);
    // abr 
  • getDateMonthNameWide ( uObj, date )

    returns a "wide" day name for the given date.

    ex,

    worldtime.getDateMonthNameWide(uobj, date);
    // abril 
  • getDateFormat ( uObj, formatType )

    returns a date format of the given formatType. valid formatType: "full", "long", "medium", "short". If no formatType given, the default format of the locale is returned.

    ex,

    worldtime.getDateFormat(uobj, 'short');
    // dd-MM-yy 
  • getTimeFormat ( uObj, formatType )

    returns a time format of the given formatType. valid formatType: "full", "long", "medium", "short". If no formatType given, the default format of the locale is returned.

    ex,

    worldtime.getTimeFormat(uobj, 'short');
    // H:mm 
  • getFormattedDate ( uObj, dateObj , formatType )

    returns the given date in the given and formatType. valid formatType: "full", "long", "medium", "short". If no formatType is given, the default format of the locale is returned.

    ex,

    worldtime.getFormattedDate(uobj, new Date(), 'short');
    // 05-04-13 
  • getFormattedTime ( uObj, dateObj , formatType )

    returns the given time in the given and formatType. valid formatType: "full", "long", "medium", "short". If no formatType is given, the default format of the locale is returned.

    ex,

    worldtime.getFormattedTime(uobj, new Date(), 'short');
    // 21:23 
  • extractFormattedDate ( uObj, dateStr , formatType )

    returns a date from a given dateStr following the given formatType. valid formatType: "full", "long", "medium", "short". If no formatType is given, the default format of the locale is returned.

    ex,

    worldtime.extractFormattedDate(uobj, '05-04-13', 'short');
    // Fri Apr 05 13 23:13:55 GMT-0700 (PDT) 

(The MIT License)

Copyright (c) 2013 Bumblehead chris@bumblehead.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.