ProductPromotion
Logo

Node.JS

made by https://0x3d.site

GitHub - floatdrop/node-cctz: ⚡️ Fast parsing, formatting and timezone manipulations for dates
⚡️ Fast parsing, formatting and timezone manipulations for dates - floatdrop/node-cctz
Visit Site

GitHub - floatdrop/node-cctz: ⚡️ Fast parsing, formatting and timezone manipulations for dates

GitHub - floatdrop/node-cctz: ⚡️ Fast parsing, formatting and timezone manipulations for dates

node-cctz Build Status

CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone.

Install

You will need C++11 compatible compiler to build this binding. For most systems this will work:

$ npm install --save cctz

If you have Ubuntu 12.04, then install clang-3.4 and set-up environment:

$ sudo apt-get install clang-3.4
$ export CXX=clang++
$ export npm_config_clang=1

Usage

const {convert, format, CivilTime} = require('cctz');

const unix = convert(new CivilTime(2015, 9, 22, 9), 'America/Los_Angeles');
console.log(format('Talk starts at %T %z (%Z)', unix, 'America/New_York'));

// => Talk starts at 12:00:00 -0400 (EDT)

API

convert(time, timezone)

Converts CivilTime to unix timestamp and vice versa.

time

Type: CivilTime or number

If time is CivilTime, then method returns Unix timestamp (without fractional part). Otherwise returns CivilTime.

timezone

Type: TimeZone or string

TimeZone objcet, that represents target timezone for converting.

format(format, unix, [timezone])

Returns formatted unix timestamp according to timezone.

format

Type: string

Format of output. See strftime documentation and Google CCTZ sources for syntax.

unix

Type: number

Unix timestamp in seconds (can have fractional part).

timezone

Type: TimeZone or string Default: local timezone

TimeZone objcet, that represents target timezone for formatting.

parse(format, input, [timezone])

Parses input string according to format string (assuming input in timezone).

Returns unix timestamp or undefined if parsing failed.

format

Type: string

Format of input argument. See strftime documentation and Google CCTZ sources for syntax.

input

Type: string

Input string to parse.

timezone

Type: TimeZone or string Default: Timezone from input or local timezone

Timezone, that should be used in parse. Timezone can be part of input:

cctz.parse('%Y-%m-%d %H:%M:%S %Ez', '2015-09-22 09:35:12+03:00');

tz(name)

Alias for cctz.load_time_zone

Use this method instead new TimeZone – because it caches TimeZone objects inside.

Returns TimeZone object.

name

Type: string

Timezone name, that should be loaded from /usr/share/zoneinfo.

now()

Alias for Math.floor(Date.now() / 1000)

Returns unix timestamp in seconds. All methods can accept timestamp with fractional milliseconds (if you need such accuracy).

CivilTime

Holder for cctz::civil_second with getters and setters for properties.

CivilTime(year = 1970, month = 1, day = 1, hour = 0, minute = 0, second = 0)

Creates CivilTime object with next properties:

  • year – getter and setter
  • month – getter and setter [1:12]
  • day – getter and setter [1:31]
  • hour – getter and setter [0:23]
  • minute – getter and setter [0:59]
  • second – getter and setter [0:59]
  • yearday – only getter [1:356]
  • weekday – only getter [0:6]

Tip: Fastest way to add amount of time is to add number of seconds to unix timestamp.

CivilTime.startOfYear()

Returns new CivilTime object with start of year.

CivilTime.startOfMonth()

Returns new CivilTime object with start of month.

CivilTime.startOfDay()

Returns new CivilTime object with start of day.

CivilTime.startOfHour()

Returns new CivilTime object with start of hour.

CivilTime.clone()

Returns cloned CivilTime object.

TimeZone

Holder for cctz::time_zone.

TimeZone(name)

Creates new object with TimeZone.

TimeZone.lookup(unix)

Returns cctz::absolute_lookup object.

TimeZone.lookup(civiltime)

Returns cctz::civil_lookup object.

TimeZone.name

Name of TimeZone.

Benchmarks

Format              (cctz) x 532,683 ops/sec ±2.80% (78 runs sampled)
                    (Date) x 191,400 ops/sec ±2.59% (81 runs sampled)
                (date-fns) x  91,772 ops/sec ±1.58% (85 runs sampled)
                  (moment) x  56,508 ops/sec ±6.35% (76 runs sampled)

Parse               (cctz) x 1,105,353 ops/sec ±0.59% (86 runs sampled)
                    (Date) x 1,200,218 ops/sec ±2.00% (82 runs sampled)
                (date-fns) x   249,225 ops/sec ±5.00% (77 runs sampled)
                  (moment) x    23,905 ops/sec ±1.91% (80 runs sampled)

Add hour            (cctz) x 6,123,083 ops/sec ±5.39% (82 runs sampled)
                    (Date) x 3,604,915 ops/sec ±1.13% (69 runs sampled)
                (date-fns) x 3,211,900 ops/sec ±2.28% (81 runs sampled)
                  (moment) x   590,854 ops/sec ±8.48% (72 runs sampled)

Convert Ut->Time    (cctz) x 653,305 ops/sec ±9.33% (68 runs sampled)
                  (moment) x 144,580 ops/sec ±2.18% (83 runs sampled)

Convert Time->Ut    (cctz) x 987,437 ops/sec ±11.68% (70 runs sampled)
                  (moment) x 154,492 ops/sec ±3.54% (82 runs sampled)

Run npm i and then npm run bench.

License

MIT © Vsevolod Strukchinsky

Articles
to learn more about the nodejs concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about NodeJS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory