npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ctoc_timezone

v1.0.2

Published

CtoCtimezone is a simple yet useful JS that is used to convert the time to client side timezone by employing minimum changes in your application. Please refer github page for detailed information.

Downloads

6

Readme

CtoC

CtoC(Convert to client timezone) is a simple yet useful script that is used to convert the time to the client side timezone by employing minimum changes in your application.CtoC capable to convert the date-time to both local and any other timezone you want it to.

This package has javascript handle that can be fetched into your code to handle the date objects. The primary purpose of this package is to eliminate the mundane code that user uses to handle timezones and necessary formats.

The package could be used for following cases:

  • Convert the date from server to local (host or browser) time.
  • Convert the date from server to ANY standard timezone(IANA) offset you want it to be.

Usage

Convert a date by using a data attribute

Return the date in the following format :

<div data-ctoc-timezone data-ctoc-time="" data-ctoc-req-zone="" data-ctoc-req-format=""</div>

| Attribute | Description | | --- | --- | | data-ctoc-timezone | Identifier for data attribute, gets removed once the date is conversion is complete. | | data-ctoc-time | is the time to be converted , should be given in a valid JS date-string format . View Date Strings | | data-ctoc-req-zone | is the timezone to convert the given date-time object.The field accepts all IANA timezones and variety of other timezone offsets. You can also give the offset in form of "+hh:mm" or "-hh:mm" or simply an integer.The Timezone offsets are available in the View TimeZones | | data-ctoc-format | is the format specifier for the date-time object. You can construct your own format using the following rules View Formats. Not defining the format gives a Date with Datestring format.|

Example :

<div data-ctoc-timezone data-ctoc-time="Mar 01 2013 05:30:00 +5:30" data-ctoc-req-zone="" data-ctoc-req-format=""></div>

Output:

`Fri Mar 01 2013 05:30:00 GMT+0530 (India Standard Time)`

For Changing Timezone :

(Default Format : "ddd MMM dd YYYY hh:mm:ss")

Using IANA format:

<div data-ctoc-timezone data-ctoc-time="Mar 01 2013 05:30:00 +5:30" data-ctoc-req-zone="America/Lima" data-ctoc-req-format=""> </div>

**Output :

`Thu Feb 28 2013 19:00:00 `

Using offset in hh:mm format:

<div data-ctoc-timezone data-ctoc-time="Mar 01 2013 05:30:00 +5:30" data-ctoc-req-zone="-5:00" data-ctoc-req-format=""</div>

Output:

Thu Feb 28 2013 19:00:00

Using Integer :

<div data-ctoc-timezone data-ctoc-time="Mar 01 2013 05:30:00 +5:30" data-ctoc-req-zone=-5 data-ctoc-req-format=""></div>

Output :

Thu Feb 28 2013 19:00:00

Changing Format:

<div data-ctoc-timezone data-ctoc-time="Mar 01 2013 05:30:00 +5:30" data-ctoc-req-zone="America/Lima" data-ctoc-req-format=" ddd Do MMM YYYY hh:mm:ss #{America}"></div>

Output:

Thu 28th Feb 2013 19:00:00 America

Convert using method call :

Changing TimeZone:

Use the toTimeZone method in CtoC.

CtoC.toTimeZone(dateobject,timeZone,format);

Here the dateobject is must paramater for the method to work while both timeZone and format considered optional.It is Date object type of JS (Date()).

In timeZone , you can pass any IANA or offset values specified in View TimeZones. Not passing or giving empty string converts to local time.

In format sepcify any of the format types in View Formats. Not passing a format or giving empty returns in default format. Example:

CtoC.toTimeZone(new Date(),"EST");

Output:

Fri Mar 1 2013 05:30:00

Changing format in toTimeZone:

CtoC.toTimeZone(new Date(),"EST","Do MMM YYYY hh:mm:ss #{EST}");

Output :

28th Feb 2013 19:00:00 EST

Changing Format:

Use the 'toFormat' method in CtoC.

CtoC.toFormat(dateobject,format)

Format accepts two parameters - dateobject the date passed in date type and an optional format in string of specifies types. View Formats

Example:

CtoC.toFormat(new Date(),"Do MMM YYYY hh:mm:ss #{EST}");

Output:

28th Feb 2013 19:00:00 EST

Default TimeZone and Format :

You can also set the default timezone and formats using the supported timezones and formats using the methods:

Default Timezone

CtoC.defaultTimeZone

**Example:

CtoC.defaultTimeZone="IST"

Default Format

CtoC.defaultFormat

Example:

CtoC.defaultFormat="Do MM YYYY , hh:mm:ss"

Note:

The order of parameters depends is as follows:

If any method or data attribute is given either format or timezone as a parameter, the call has higher precedence to that of default values been set.

If the defualt values are set and the method has no params then the default values are considered.

If there are no default values and method params , then the timezone is set to Local and the default format will be Date String.

This project is licensed under the MIT License - see the LICENSE.md file for details