worldtime

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

npm install worldtime
14 downloads in the last month

worldtime

(c)Bumblehead, 2013 MIT-license

Overview:

NOTE:
This software is a work in progress and may be unusable at this time.

worldtime provides methods for manipulating international dates, converting dates to and from unicode format.

worldtime uses the [official Unicode ldml-JSON files][2] for formatting and parsing international dates and times. Use json-locale to get these files and optimise them.

worldtime extends simpletime. no libraries are required. just simpletime, worldtime and unicode JSON files.

because worldtime extends simpletime, constructed worldtime objects will have the same methods and properties that are defined on simpletime objects.

what's good about this script:

  • format and unformat international time using unicode forms
  • create and use YMDArr objects to simplify time manipulation
  • it may be used in a browser or node.js ecmascipt environment

Install:

worldtime may be downloaded directly or installed through npm.


Test:

to run tests, use npm test from a shell.

 $ npm test

GET STARTED:

  1. Construct a WorldTime Object

    construct a worldtime object and begin using it.

    worldtime is constructed with an object as the first parameter, and a language identifier as the second parameter.

    var WorldTime = require('../worldtime');
    var es_CLObj = require('./locale/es_CL.json');
    var worldTimeObj = WorldTime(es_CLObj, 'es_CL'); var d = worldTimeObj.extractFormattedDate('05-04-2013', 'medium'); console.log(d); // (date) Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var f = worldTimeObj.getFormattedTime(d, 'medium'); console.log(f); // 05-04-2013

METHODS:

  • getCalendarObj ( calendarType )
    returns a calendar object from the unicode file.

    the following calendars are defined by the unicode files and are valid calendarTypes:

    "buddhist",
    "chinese",
    "coptic",
    "dangi",
    "ethiopic",
    "ethiopicAmeteAlem",
    "gregorian",
    "hebrew",
    "indian",
    "islamic",
    "islamicCivil",
    "japanese",
    "persian",
    "roc"

  • getCalendarUnit ( unitType )

    returns a calendar unit object from the unicode file.

    the following units are defined by the unicode files and are valid unitTypes:

    "months",
    "days",
    "quarters",
    "eras",
    "dateFormats",
    "timeFormats",
    "dateTimeFormats",
    "fields"

  • getMonthNameFormatObj ( monthType )

    returns an object of month names for the given month type

    by default, months are provided by the gregorian calendar object

    the following month types are defined by the unicode files and are valid monthTypes:

    "abbreviated",
    "narrow",
    "wide"

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getMonthNameFormatObj('abbreviated'); console.log(result); // { // "1": "ene", // "2": "feb", // "3": "mar", // "4": "abr", // "5": "may", // "6": "jun", // "7": "jul", // "8": "ago", // "9": "sep", // "10": "oct", // "11": "nov", // "12": "dic" // }
  • getNumericMonthNameAbbrev ( monthNum )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getNumericMonthNameAbbrev('1'); console.log(result); // ene
  • getNumericMonthNameWide ( monthNum )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getNumericMonthNameWide('1'); console.log(result); // enero
  • getDayNameFormatObj ( monthType )

    returns an object of day names for the given day type

    by default, months are provided by the gregorian calendar object

    the following day types are defined by the unicode files:

    "abbreviated",
    "narrow",
    "wide"

   var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
var result = worldTimeObj.getDayNameFormatObj('abbreviated'); console.log(result); // { // "sun": "dom", // "mon": "lun", // "tue": "mar", // "wed": "miC)", // "thu": "jue", // "fri": "vie", // "sat": "sC!b" // }
  • getStrDayNameAbbrev ( dayStr )

    returns a day name of the abbreviated day type for the given dayStr

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getStrDayNameAbbrev('mon'); console.log(result); // lun
  • getStrDayNameWide ( dayStr )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getStrDayNameWide('mon'); console.log(result); // lunes
  • getDateMonthNameAbbrev ( dayStr )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    // Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var date = new Date(1365222221485);
    var result = worldTimeObj.getDateMonthNameAbbrev(date); console.log(result); // abr
  • getDateMonthNameWide ( dayStr )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    // Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var date = new Date(1365222221485);
    var result = worldTimeObj.getDateMonthNameWide(date); console.log(result); // abril
  • getDateFormat ( formatType )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getDateFormat('short'); console.log(result); // dd-MM-yy
  • getTimeFormat ( formatType )

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

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getTimeFormat('short'); console.log(result); // H:mm
  • getFormattedDate ( dateObj , formatType )

    returns a formatted date of the given dateObj and formatType ( full, long, medium, short ). If no formatType is given, the default format of the locale is returned.

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    // Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var date = new Date(1365222221485);
    var result = worldTimeObj.getFormattedDate(date, 'short'); console.log(result); // 05-04-13
  • getFormattedTime ( dateObj , formatType )

    returns a formatted date of the given dateObj and formatType ( full, long, medium, short ). If no formatType is given, the default format of the locale is returned.

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    // Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var date = new Date(1365222221485);
    var result = worldTimeObj.getFormattedTime(date, 'short'); console.log(result); // 21:23
  • extractFormattedDate ( dateStr , formatType )

    returns a date of the given formattted dateStr and formatType ( full, long, medium, short ). If no formatType is given, the default format of the locale is returned.

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    // Fri Apr 05 2013 21:23:41 GMT-0700 (PDT) var date = '05-04-13'; var result = worldTimeObj.extractFormattedDate(date, 'short'); console.log(result); // Fri Apr 05 13 23:13:55 GMT-0700 (PDT)
  • getBaseMonthsArr ( formatType )

    returns an array of months for the given formatType ( full, long, medium, short ).

    var worldTimeObj = WorldTime(es_CLObj, 'es_CL');
    var result = worldTimeObj.getBaseMonthsArr('short'); console.log(result); //

Contributions:

Contributions are welcome. If you've found an issue and you'd like to send me an email about it feel free to do that.

I initially wrote worldtime while I was building an international software application on a job. I have changed jobs and I'm no longer testing or developing this script for a production environment. If you find issues please report them or send a fix.


License:

(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.

npm loves you