Giter Site home page Giter Site logo

node-time's Introduction

node-time

"time.h" bindings for Node.js.

Build Status Build Status

This module offers simple bindings for the C time.h APIs. It also offers an extended native Date object with getTimezone() and setTimezone() functions, which aren't normally part of JavaScript.

Installation

node-time is available through npm:

$ npm install time

Example

var time = require('time');

// Create a new Date instance, representing the current instant in time
var now = new time.Date();

now.setTimezone("America/Los_Angeles");
// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-8

now.setTimezone("America/New_York");
// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-5


// You can also set the timezone during instantiation
var azDate = new time.Date(2010, 0, 1, 'America/Phoenix');
azDate.getTimezone(); // 'America/Phoenix'

Extending the global Date object

node-time provides a convenient time.Date object, which is its own Date constructor independent from your own (or the global) Date object. There are often times, however, when you would like the benefits of node-time on all Date instances. To extend the global Date object, simply pass it in as an argument to the node-time module when requiring:

var time = require('time')(Date);

var d = new Date();
d.setTimezone('UTC');

API

Date() -> Date

new time.Date()

new time.Date(millisecondsFromUTC)

new time.Date(dateString [, timezone ])

new time.Date(year, month, day [, hour, minute, second, millisecond ] [, timezone ])

A special Date constructor that returns a "super" Date instance, that has magic timezone capabilities! You can also pass a timezone as the last argument in order to have a Date instance in the specified timezone.

var now = new time.Date();
var another = new time.Date('Aug 9, 1995', 'UTC');
var more = new time.Date(1970, 0, 1, 'Europe/Amsterdam');

date.setTimezone(timezone [, relative ]) -> Undefined

Sets the timezone for the Date instance. By default this function makes it so that calls to getHours(), getDays(), getMinutes(), etc. will be relative to the timezone specified. If you pass true in as the second argument, then instead of adjusting the local "get" functions to match the specified timezone, instead the internal state of the Date instance is changed, such that the local "get" functions retain their values from before the setTimezone call.

date.setTimezone("America/Argentina/San_Juan")

// Default behavior:
a = new time.Date()
a.toString()
// 'Wed Aug 31 2011 09:45:31 GMT-0700 (PDT)'
a.setTimezone('UTC')
a.toString()
// 'Wed Aug 31 2011 16:45:31 GMT+0000 (UTC)'

// Relative behavior:
b = new time.Date()
b.toString()
// 'Wed Aug 31 2011 10:48:03 GMT-0700 (PDT)'
b.setTimezone('UTC', true)
b.toString()
// 'Wed Aug 31 2011 10:48:03 GMT+0000 (UTC)'

date.getTimezone() -> String

Returns a String containing the currently configured timezone for the date instance. This must be called after setTimezone() has been called.

date.getTimezone();
  // "America/Argentina/San_Juan"

date.getTimezoneAbbr() -> String

Returns the abbreviated timezone name, also taking daylight savings into consideration. Useful for the presentation layer of a Date instance.

date.getTimezoneAbbr();
  // "ART"

Date.parse(dateStr [, timezone ]) -> Number

Same as the native JavaScript Date.parse() function, only this version allows for a second, optional, timezone argument, which specifies the timezone in which the date string parsing will be resolved against. This function is also aliased as time.parse().

time.Date.parse("1970, January 1");  // <- Local Time
  // 28800000
time.Date.parse("1970, January 1", "Europe/Copenhagen");
  // -3600000
time.Date.parse("1970, January 1", "UTC");
  // 0

extend(date) -> Date

Transforms a "regular" Date instance into one of node-time's "extended" Date instances.

var d = new Date();
// `d.setTimezone()` does not exist...
time.extend(d);
d.setTimezone("UTC");

time() -> Number

Binding for time(). Returns the number of seconds since Jan 1, 1900 UTC. These two are equivalent:

time.time();
  // 1299827226
Math.floor(Date.now() / 1000);
  // 1299827226

tzset(timezone) -> Object

Binding for tzset(). Sets up the timezone information that localtime() will use based on the specified timezone variable, or the current process.env.TZ value if none is specified. Returns an Object containing information about the newly set timezone, or throws an Error if no timezone information could be loaded for the specified timezone.

time.tzset('US/Pacific');
  // { tzname: [ 'PST', 'PDT' ],
  //   timezone: 28800,
  //   daylight: 1 }

localtime(Number) -> Object

Binding for localtime(). Accepts a Number with the number of seconds since the Epoch (i.e. the result of time()), and returns a "broken-down" Object representation of the timestamp, according the the currently configured timezone (see tzset()).

time.localtime(Date.now()/1000);
  // { seconds: 38,
  //   minutes: 7,
  //   hours: 23,
  //   dayOfMonth: 10,
  //   month: 2,
  //   year: 111,
  //   dayOfWeek: 4,
  //   dayOfYear: 68,
  //   isDaylightSavings: false,
  //   gmtOffset: -28800,
  //   timezone: 'PST' }

currentTimezone -> String

The currentTimezone property always contains a String to the current timezone being used by node-time. This property is reset every time the tzset() function is called. Individual time.Date instances may have independent timezone settings than what this one is...

node-time's People

Contributors

atinux avatar blax avatar dresende avatar goffrie avatar hmalphettes avatar imyller avatar jclulow avatar kkoopa avatar motammi avatar retrofox avatar santigimeno avatar shosokawa avatar tootallnate avatar zenoamaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-time's Issues

Possible bug when using dateString with UTC timezone

If I do this:

var date  = new time.Date('2012-10-27', 'UTC');
console.log(date.toString());

it prints this:

'Sat Oct 27 2012 02:00:00 GMT+0000 (UTC)'

Notice that the time is 02:00:00. This is the result that I had expected:

'Sat Oct 27 2012 00:00:00 GMT+0000 (UTC)'

If I give '2012-10-27T00:00:00Z' to the constructor it gives the same result. And yes my local timezone at that date is GMT+0200.

Have I misunderstood something or is this a bug?

Possible race condition when loading node-time and immediately using it

My application uses node-time to look up timezone offsets. It uses node's cluster module to start 5 workers. When we're experiencing high throughput and try to bring up a new process, many times the workers die with errors related to being unable to load timezones:

Uncaught Exception: Error: Unknown Timezone: 'Europe/Moscow'

{ message: 'Unknown Timezone: \'Europe/Moscow\'',
 name: 'Error',
 stack: 
  [ 'Error: Unknown Timezone: \'Europe/Moscow\'',
    '    at Function.tzset (.../node_modules/time/index.js:139:15)',
    '    at Date.setTimezone (.../node_modules/time/index.js:241:18)',
    '    at Object.localTime (.../lib/geo_timezone.js:70:11)',
 ...
    '    at HTTPServer.Server.handle (.../node_modules/connect/lib/http.js:217:3)',
    '    at HTTPServer.EventEmitter.emit (events.js:98:17)',
    '    at HTTPParser.parser.onIncoming (http.js:2108:12)',
    '    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)',
    '    at Socket.socket.ondata (http.js:1966:22)',
    '    at TCP.onread (net.js:525:27)' ] }

After a while, the load balancer backs off a bit and the process is able to start. It looks to me like most things in node-time are synchronous, but is there a way for me to ensure the timezones are fully loaded before I start listening for requests?

Segmentation fault libc.so.6

Hi,
one, max twice a day I have a segfault on production. We have two server configurations, both are affected. npm time version 0.11.0. Can't reproduce it.

CentOS release 6.4 (Final) ldd (GNU libc) 2.12 node v0.10.24
Debian GNU/Linux 6.0 ldd (Debian EGLIBC 2.11.3-4) 2.11.3 node v0.10.23

Program terminated with signal 11, Segmentation fault.
0  0x00007fa42b797d5f in __strlen_sse42 () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64 libgcc-4.4.7-3.el6.x86_64 libstdc++-4.4.7-3.el6.x86_64 libxml2-2.7.6-12.el6_4.1.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) backtrace
0  0x00007fa42b797d5f in __strlen_sse42 () from /lib64/libc.so.6
1  0x00000000005b6b8a in v8::String::NewSymbol(char const*, int) ()
2  0x00007fa42b26190e in Time::Mktime(v8::Arguments const&) () from /opt/livechat/rest-api/node_modules/time/build/Release/time.node
3  0x000014e366bec141 in ?? ()

install problem in Ubuntu12.04 64bit

How to solve ?
Thx!

npm install time
npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/debug

[email protected] install /usr/share/nginx/www/countly/api/node_modules/time
node-gyp rebuild

gyp: /root/.node-gyp/0.10.17/common.gypi not found (cwd: /usr/share/nginx/www/countly/api/node_modules/time) while reading includes of binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.5.0-23-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/share/nginx/www/countly/api/node_modules/time
gyp ERR! node -v v0.10.17
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

node-time not working on non-Linux platforms

So I tried deploying a project using node-time to Cygwin and to Joyent. I could not get node-time to compile and install. After investigation, (I'm no C expert), I concluded two of the methods used (noted as only available in glibc) cannot be found on platforms like CygWin and Solaris (which is Joyent).

I forked the repo in an attempt to make it platform-capable. Unfortunately, my apologies: I'm just not well-versed in C. I found preprocessor code that should work, as well as the changes necessary to time.cc.

Reference: http://redmine.lighttpd.net/attachments/1080/solaris-timezone.patch
Fork: https://github.com/clintandrewhall/node-time
My configuration: https://github.com/clintandrewhall/node-time/blob/master/configure.ac

Changes to time.cc:

  #if defined(HAVE_STRUCT_TM_GMTOFF)
  // Only available with glibc's "tm" struct
  obj->Set(String::NewSymbol("gmtOffset"), Integer::New(timeinfo->tm_gmtoff) );
  obj->Set(String::NewSymbol("timezone"), String::NewSymbol(timeinfo->tm_zone) );
  # elif defined(HAVE_TIMEZONE_ALTZONE)
  long scd;
  if(tm.tm_isdst > 0)
    scd = altzone;
  else
    scd = timezone;

    obj->Set(String::NewSymbol("gmtOffset"), Integer::New(abs(scd)));
    obj->Set(String::NewSymbol("timezone"), Integer::New(abs(scd)));
  #endif

In testing, though, I have no idea how to port the configure.ac statements to WAF. I'm simply stuck.

Am I on the right track here? Since Cygwin is currently the only means for a Windows machine to run Node, this may become a show-stopper problem with node-time.

npm failed to install time with make not found error

When i try to install time on my node server i get the below error:

> [email protected] install /var/www/track/node_modules/time
> node-gyp rebuild

gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack     at F (/usr/lib/nodejs/npm/node_modules/which/which.js:43:28)
gyp ERR! stack     at E (/usr/lib/nodejs/npm/node_modules/which/which.js:46:29)
gyp ERR! stack     at /usr/lib/nodejs/npm/node_modules/which/which.js:57:16
gyp ERR! stack     at Object.oncomplete (fs.js:297:15)
gyp ERR! System Linux 3.2.0-31-virtual
gyp ERR! command "node" "/usr/lib/nodejs/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/track/node_modules/time
gyp ERR! node -v v0.8.15
gyp ERR! node-gyp -v v0.7.1
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-31-virtual
npm ERR! command "nodejs" "/usr/bin/npm" "install" "time"
npm ERR! cwd /var/www/track
npm ERR! node -v v0.8.15
npm ERR! npm -v 1.1.66
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /var/www/track/npm-debug.log
npm ERR! not ok code 0

version that compiles with 0.8.x?

I swear 0.10.x used to work but now it's failing for us and 0.9.2 as well, non-helpful log:

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time

time.Date() incorrect for Jan 31, 2010 19:00 GMT

The following line seems to be returning "Sun Jan 03 2010 19:00:00 GMT+0000 (UTC)"

var newTime = new time.Date(2010, 0, 31, 19, 0, 0, 0, 'UTC');
var newTimeString = newTime.toString();

I think this should be returning "Sun Jan 31..." instead. I really appreciate the help with this - if I'm missing something, I'm sure not seeing it.

Thanks,
-Dan

The code I need looks a little more like this but I can't seem to get the hard-coded values to work so that seems like the place to start.

var newTime = new time.Date(startTime.getUTCFullYear(), startTime.getUTCMonth(), startTime.getUTCDate(), startTime.getUTCHours(), startTime.getUTCMinutes(), 0, 0);//, 'UTC');
newTime.setTimezone('UTC');
newTime.setTimezone(timezone);

SetTimezone with relative=true doesn't work right

Let's say you have a time object representing Apr 15 at 10:15 PM in Pacific time, and you call this on it:

time.setTimezone("US/Eastern", true);

It turns into this:

Mon Apr 15 2013 01:15:00 GMT-0400 (EDT)

But the right answer is this:

Tue Apr 16 2013 01:15:00 GMT-0400 (EDT)

Specifically it needs to add one to the day to make it Apr 16 instead of Apr 15. Otherwise they do not represent the same moment in time (it'll be off by 24 hours).

Strange behavior

Hi,

time = require ('time')
a = new time.Date()
Fri, 11 May 2012 06:24:53 GMT
b = new time.Date()
Fri, 11 May 2012 06:24:58 GMT
a.toString()
'Fri May 11 2012 11:54:53 GMT+0530 (IST)'
b.toString()
'Fri May 11 2012 11:54:58 GMT+0530 (IST)'

a.setTimezone('UTC') // affects objects created after this call

a.toString()
'Fri May 11 2012 06:24:53 GMT+0000 (UTC)' // correct behaviour
b.toString()
'Fri May 11 2012 11:54:58 GMT+0530 (IST)' // correct behaviour
c = new time.Date()
Fri, 11 May 2012 06:25:43 GMT
c.toString()
'Fri May 11 2012 06:25:43 GMT+0000 (UTC)' // wrong behavior why 'c' is in UTC ?

New time.Date() objects are affected after calling setTimezone() in any one of the time.Date() object ?

Note: I am using nodejs 0.6.16 and time 0.8.1

With Pacific Time as local time, setting 2012-3-11 2:30 in another timezone gives wrong time

Currently, the result is

> t = new time.Date("2012-3-11 2:30", "Asia/Shanghai")
...
> t.toString()
'Sun Mar 11 2012 01:30:00 GMT+0800 (CST)'

It should be

> t = new time.Date("2012-3-11 2:30", "Asia/Shanghai")
...
> t.toString()
'Sun Mar 11 2012 02:30:00 GMT+0800 (CST)'

Note, 2012-3-11 2:30 doesn't exist in America/Los_Angeles as it's in the middle of DST cut-off. However, Asia/Shanghai does not observe DST and 2012-3-11 2:30 is a perfect valid time.

Segfault in 0.9.1

After upgrading one of our servers to time 0.9.1, we've been experiencing reproducible segfaults when running a certain service. Seems like f6f5aed is the probable cause. I ran gdb on my local machine, here's the segfault:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
Time::Localtime (args=<value temporarily unavailable, due to optimizations>) at ../src/time.cc:71
71  ../src/time.cc: No such file or directory.
    in ../src/time.cc

And the backtrace:

#0  Time::Localtime (args=<value temporarily unavailable, due to optimizations>) at ../src/time.cc:71
#1  0x00003327db65df5b in ?? ()
#2  0x00003327db65cbb8 in ?? ()
#3  0x00003327db65c7a6 in ?? ()
#4  0x00003327db30a96e in ?? ()
#5  0x00003327db32428f in ?? ()
#6  0x00003327db9e7dc8 in ?? ()
#7  0x00003327db32851e in ?? ()
#8  0x00003327db6eee99 in ?? ()
#9  0x00003327db30a96e in ?? ()
#10 0x00003327db3245e1 in ?? ()
#11 0x00003327db3118b7 in ?? ()
#12 0x00000001001857fd in v8::internal::Invoke ()
#13 0x0000000100293975 in v8::internal::Runtime_Apply ()
#14 0x00003327db30618e in ?? ()
#15 0x00003327db66bd16 in ?? ()
#16 0x00003327db30a96e in ?? ()
#17 0x00003327db328518 in ?? ()
#18 0x00003327db808cbb in ?? ()
#19 0x00003327db808a9c in ?? ()
#20 0x00003327db30a96e in ?? ()
#21 0x00003327db328518 in ?? ()
#22 0x00003327db80dc60 in ?? ()
#23 0x00003327db30a96e in ?? ()
#24 0x00003327db3245e1 in ?? ()
#25 0x00003327db3118b7 in ?? ()
#26 0x00000001001857fd in v8::internal::Invoke ()
#27 0x0000000100293975 in v8::internal::Runtime_Apply ()
#28 0x00003327db30618e in ?? ()
#29 0x00003327db66bf85 in ?? ()
#30 0x00003327db30a96e in ?? ()
#31 0x00003327db3f8c65 in ?? ()
#32 0x00003327db30a96e in ?? ()
#33 0x00003327db8262e1 in ?? ()
#34 0x00003327db30a96e in ?? ()
#35 0x00003327db328518 in ?? ()
#36 0x00003327db3f8faf in ?? ()
#37 0x00003327db30a96e in ?? ()
#38 0x00003327db8256d5 in ?? ()
#39 0x00003327db30a96e in ?? ()
#40 0x00003327db328518 in ?? ()
#41 0x00003327db3f8faf in ?? ()
#42 0x00003327db8253b2 in ?? ()
#43 0x00003327db66ab29 in ?? ()
#44 0x00003327db3245e7 in ?? ()
#45 0x00003327db3118b7 in ?? ()
#46 0x00000001001857fd in v8::internal::Invoke ()
#47 0x0000000100142220 in v8::Function::Call ()
#48 0x0000000100005bb7 in node::MakeCallback ()
#49 0x0000000100005c7b in node::MakeCallback ()
#50 0x000000010001d02a in node::StreamWrap::OnReadCommon ()
#51 0x0000000100127a88 in uv__stream_io ()
#52 0x000000010012e144 in uv__io_poll ()
#53 0x0000000100121d7f in uv_run ()
#54 0x0000000100009d40 in node::Start ()
#55 0x0000000100000cf4 in start ()

Install Errors

NPM suggested I put this here:

gyp ERR! rebuild error Error: Command failed: Unknown option: --
gyp ERR! rebuild error usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
gyp ERR! rebuild error Try `python -h' for more information.
gyp ERR! rebuild error 
gyp ERR! rebuild error     at ChildProcess.exithandler (child_process.js:282:15)
gyp ERR! rebuild error     at ChildProcess.emit (events.js:70:17)
gyp ERR! rebuild error     at maybeExit (child_process.js:362:16)
gyp ERR! rebuild error     at Socket.<anonymous> (child_process.js:467:7)
gyp ERR! rebuild error     at Socket.emit (events.js:67:17)
gyp ERR! rebuild error     at Array.0 (net.js:335:10)
gyp ERR! rebuild error     at EventEmitter._tickCallback (node.js:190:38)
gyp ERR! not ok 
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 2.6.9-023stab048.6-enterprise
npm ERR! command "node" "/usr/bin/npm" "install" "time"
npm ERR! cwd /var/www/vhosts/[MYSERVER]/httpdocs
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.40
npm ERR! code ELIFECYCLE
npm ERR! stack Error: [email protected] install: `node-gyp rebuild`
npm ERR! stack `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR! stack     at ChildProcess.<anonymous> (/usr/lib/nodejs/npm/lib/utils/exec.js:56:20)
npm ERR! stack     at ChildProcess.emit (events.js:70:17)
npm ERR! stack     at maybeExit (child_process.js:362:16)
npm ERR! stack     at Process.onexit (child_process.js:398:5)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /var/www/vhosts/[MYSERVER]/httpdocs/npm-debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1

Segmentation Faults

Hi there,

we just want to let you know that we see segmentation faults in node-time regularly.

We only have two patterns invoking node-time:

var now = new time.Date();
now.setTimezone('Europe/Berlin');
return now.getYear() + "..." + now.getMonth() + "..." + now.getDate();

and

var now = new time.Date(Date.parse('some date in YYYY-MM-DD HH:MM:SS +0000 format'));
now.setTimezone('Europe/Berlin');
return now.getYear() + "..." + now.getMonth() + "..." + now.getDate();

The first one is called multiple times per second, the second one only irregularly (5-10x per hour). Every now and then the second one fails with a seg fault:

Nov 19 12:13:27 ip-10-229-19-31: PID 18233 received SIGSEGV for address: 0x0
Nov 19 12:13:27 ip-10-229-19-31: /var/node/node_modules/segvcatcher/build/Release/segvhandler_native.node(+0x18a4)[0x7f9ff8c6e8a4]
Nov 19 12:13:27 ip-10-229-19-31: /lib/libpthread.so.0(+0xf8f0)[0x7f9ff92038f0]
Nov 19 12:13:27 ip-10-229-19-31: /lib/libc.so.6(+0x83052)[0x7f9ff8ef4052]
Nov 19 12:13:27 ip-10-229-19-31: NodeProcessTitleReplaced (_ZN2v86String9NewSymbolEPKci+0xa6)[0x6d1476]
Nov 19 12:13:27 ip-10-229-19-31: /var/node/node_modules/time/build/Release/time.node(_ZN4Time5TzsetERKN2v89ArgumentsE+0x7e)[0x7f9ff865a8be]
Nov 19 12:13:27 ip-10-229-19-31: [0x39f34348fd1b]

We created this with node-segfault-handler.

The timezone's on our servers is resolved to Etc/UTC. We are runing node 0.8.8 with node-time 0.8.3.

We are currently trying to find the root cause, but any help or tips are appreciated :)

Cheers,
ZeissS

cant install

this is the error i get when i npm install it
[email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild

Cannot install on windows

cannot install on windows box

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com>npm install time
npm WARN package.json somestuff@0.0.1 No README.md file found!
npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings

> time@0.9.2 install Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com\nod
e_modules\time
> node-gyp rebuild


Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com\node_modules\time>node "
C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\no
de-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\nod
e_modules\node-gyp\lib\configure.js:113:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:82:11
gyp ERR! stack     at Object.oncomplete (fs.js:297:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com\node_module
s\time
gyp ERR! node -v v0.8.21
gyp ERR! node-gyp -v v0.8.4
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "time"
npm ERR! cwd Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     Z:\F-Drive\Projects\NOTE.JS\SomeStaff\api.somestaff.com\npm-debug.l
og
npm ERR! not ok code 0

TypeError: Cannot read property 'tzname' of undefined when setting timezone to Asia/Bangkok.

When setting the timezone to Asia/Bangkok, it throws:

TypeError: Cannot read property 'tzname' of undefined

The code is like this:

a = new Date();
require('time').extend(a);
a.setTimezone('Asia/Bangkok');
console.log(a.toString()); // error

However, setting it to different timezone that works first, then set to Asia/Bangkok makes it work:

a = new Date();
require('time').extend(a);
a.setTimezone('UTC');
a.setTimezone('Asia/Bangkok');
console.log(a.toString()); // error

Cannot require without crash.

Hi there - and thank you for all the work you've put into this module!

I try to use this module and installed it by "npm install time". However, just requiring it throws this error:

[path_to_my_project]/node_modules/time/node_modules/bindings/bindings.js:83
        throw e
              ^
Error: [path_to_my_project]/node_modules/time/build/Release/time.node: failed to map segment from shared object: Operation not permitted
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at bindings ([path_to_my_project]/node_modules/time/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> ([path_to_my_project]/node_modules/time/index.js:8:35)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

I think it might be connected to cron that I'm also using but I'm not experienced enough to really figure it out yet. Any ideas? Help would really be appreciated.

Installation not working on FreeBSD

Hi,
when trying to install node-time with npm install time on FreeBSD (8.3-RELEASE-p4), I get an error because the time.h on FreeBSD is kindly different in the following points:

  • no declaration for daylight
  • different type for timezone (char *timezone(int, int);)

(See time.h for FreeBSD here: https://github.com/freebsd/freebsd/blob/master/include/time.h)

I get the following error when trying to install it:

npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install /root/node_modules/time
> node-gyp rebuild

gmake: Entering directory `/root/node_modules/time/build'
  CXX(target) Release/obj.target/time/src/time.o
../src/time.cc: In static member function 'static v8::Handle<v8::Value> Time::Tzset(const v8::Arguments&)':
../src/time.cc:53: error: no matching function for call to 'v8::Number::New(char* (&)(int, int))'
/root/.node-gyp/0.10.17/deps/v8/include/v8.h:1377: note: candidates are: static v8::Local<v8::Number> v8::Number::New(double)
../src/time.cc:57: error: 'daylight' was not declared in this scope
gmake: *** [Release/obj.target/time/src/time.o] Error 1
gmake: Leaving directory `/root/node_modules/time/build'
gyp ERR! build error
gyp ERR! stack Error: `gmake` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/node_modules/node-gyp/lib/build.js:256:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System FreeBSD 8.3-RELEASE-p4
gyp ERR! command "node" "/root/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /root/node_modules/time
gyp ERR! node -v v0.10.17
gyp ERR! node-gyp -v v0.9.2
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

When trying to fix it manually (adding an external int daylight; and changing the type of timezone to double timezone;) in the systems time.h, the installation over npm works, but then I get a runtime error in my node script:

Error: /root/node_modules/time/build/Release/time.node: Undefined symbol "daylight"

Thank you for looking into this problem!

Unknown Timezone 'Etc/GMT 10'

I'm seeing an error being thrown when passing in 'Etc/GMT 10' to setTimezone.

/data/app/user_service/current/node_modules/time/index.js:153
    throw err;
          ^
Error: Unknown Timezone: 'Etc/GMT 10'
    at Function.tzset (/data/app/user_service/current/node_modules/time/index.js:149:15)
    at Date.setTimezone (/data/app/user_service/current/node_modules/time/index.js:251:18)

The 'Etc' is a valid area prefix in which the offset is reversed.

Install failed on Windows. I'm sad :-)

I just typed : npm install time
and I goy that :

npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug

> [email protected] install D:\temp\node_modules\time
> node-gyp rebuild


D:\temp\node_modules\time>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild 
Traceback (most recent call last):
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\gyp", line 15, in <module>
    import gyp
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 8, in <module>
    import gyp.input
  File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 15, in <module>
    import multiprocessing
ImportError: No module named multiprocessing
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:415:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.0.6002
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\temp\node_modules\time
gyp ERR! node -v v0.10.10
gyp ERR! node-gyp -v v0.9.6
gyp ERR! not ok 
npm ERR! weird error 1
npm ERR! not ok code 0

Implement a 'listTimezones()' function

I want a listTimezones() function. It's going to have to be implemented in JavaScript, since there's no C function that easily does this for us.

  1. It first needs to determine the path of the directory containing all the "zoneinfo" files. They are located in:
    • The path specified in the process.env.TZDATA variable, for manually setting the location
    • /usr/share/zoneinfo - default location for newer libc versions
    • /usr/lib/zoneinfo - default location for older versions of libc
  2. Once we're sure of the zoneinfo dir, we need to recursively fs.readdir() it. Synchronous pseudo-logic:
    1. Set "path" to the zoneinfo root dir.
    2. fs.readdir() "path".
    3. With the results, fs.stat() each file. ForEach stat'd file:
      1. If the filename contains a ., then continue;. Since no timezone names contain a period, and there's some other files in the zoneinfo dir that we want to ignore (zone.tab).
      2. If the file is a directory, then set "path" to the filename, and restart at 1. above
      3. If it's a file, then append it's (full) name (to create a valid "timezone") to the "results" Array
    4. Return the "results" array (in a callback)...

It would also be cool to allow for a "prefix" argument to the function, which would help minimize the needed amount of recursive filesystem traversing.

Proposed API:

// Get *all* valid timezones
time.listTimezones(function(err, zones) {
  if (err) throw err;
  // "zones" is an Array of all valid timezone names
});

// Get all valid timezones beginning with "America"
time.listTimezones("America", function(err, zones) {
  if (err) throw err;
  // "zones" now only contains an Array of valid timezones beginning with "America"
});

I'll get around to implementing it someday, unless somebody else wants to beat me to it!

Doesn't install on RedHat CentOS 5

error [email protected] install: node-gyp rebuild
344 error sh "-c" "node-gyp rebuild" failed with 1
345 error Failed at the [email protected] install script.
345 error This is most likely a problem with the time package,
345 error not with npm itself.
345 error Tell the author that this fails on your system:
345 error node-gyp rebuild
345 error You can get their info via:
345 error npm owner ls time
345 error There is likely additional logging output above.
346 error System Linux 2.6.18-028stab099.3
347 error command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "time"
348 error cwd /root/projects/countly-server/api
349 error node -v v0.8.3
350 error npm -v 1.1.43
351 error code ELIFECYCLE
352 error stack Error: [email protected] install: node-gyp rebuild
352 error stack sh "-c" "node-gyp rebuild" failed with 1
352 error stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/exec.js:56:20)
352 error stack at ChildProcess.EventEmitter.emit (events.js:91:17)
352 error stack at Process._handle.onexit (child_process.js:674:10)
353 verbose exit [ 1, true ]

Install fails on RedHat Linux

Install fails with the following output:

npm install time

npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings

[email protected] install /home/kmori/server/node_modules/time
node-gyp rebuild

info it worked if it ends with ok
Traceback (most recent call last):
File "/home/kmori/.node-gyp/0.6.18/tools/gyp_addon", line 14, in ?
import gyp
File "/usr/lib/nodejs/node-gyp/legacy/tools/gyp/pylib/gyp/init.py", line 8, in ?
import gyp.input
File "/usr/lib/nodejs/node-gyp/legacy/tools/gyp/pylib/gyp/input.py", line 14, in ?
import gyp.common
File "/home/.node-gyp/0.6.18/tools/gyp/pylib/gyp/common.py", line 373
with open(source_path) as source_file:
^
SyntaxError: invalid syntax
spawn /usr/bin/python [ '/home/kmori/.node-gyp/0.6.18/tools/gyp_addon',
'binding.gyp',
'-I/home/server/node_modules/time/build/config.gypi',
'-f',
'make' ]
ERR! Error: gyp_addon failed with exit code: 1
at ChildProcess.onCpExit (/usr/lib/nodejs/node-gyp/lib/configure.js:226:16)
at ChildProcess.emit (events.js:70:17)
at maybeExit (child_process.js:362:16)
at Process.onexit (child_process.js:398:5)
ERR! not ok

npm ERR! [email protected] install: node-gyp rebuild
npm ERR! sh "-c" "node-gyp rebuild" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls time
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.18-238.9.1.el5xen
npm ERR! command "nodejs" "/usr/bin/npm" "install" "time"
npm ERR! cwd /home/server
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.19
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] install: node-gyp rebuild
npm ERR! message sh "-c" "node-gyp rebuild" failed with 1
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/server/npm-debug.log
npm not ok

Very, Very Slow!

Hi! We use node-time in a little weather service we built (http://forecast.io/). We think it's really great and we couldn't do what we do without it. (And we love you for it!)

However, it's far, far too slow! No, I mean really really too slow. Here's a quick benchmark of creating a 1000 Date() objects and setting their hours, minutes, seconds, and milliseconds to zero:

native: 10ms
time: 428ms
time w/ tz: 9113ms

Yes, that's nine hundred times slower: it takes 9ms to do a simple operation on a time.Date() object.

Native is simply doing these operations on a Date() object in the current timezone. Time is doing these operations on a time.Date() object, setting the timezone to the current system timezone (in my case, "America/New_York"). Time w/ TZ is doing these operations on a time.Date() object, and setting the timezone to any other timezone (in the case above, "America/Chicago").

We have to do such operations in our API several hundred times in order to fulfill a request. We're working on decreasing that number, but either way the latency is ridiculous.

(Incidentally, what we currently do is just look up the timezone offset once per API request, and run with it from there, doing all of the math on native Date() objects. Sadly, since our API returns data forecasted over the next week, if the timezone offset changes during the next week--such as for Daylight Savings Time--then our timestamps are off by an hour and bad things happen! This is what we're currently dealing with, and why we're trying to move to making heavier use of node-time.)

I'm happy to spend some time working on this, but I wanted to write you first:

  • Why does using a timezone other than the current system timezone take so much longer?
  • All we really need is a way to quickly look up the offset for a given timezone at a given time, taking DST and such into account. If it's simpler, perhaps there's a quick-and-easy way to get at this information?

I've included my benchmark program below, it's really trivial.

Thanks!


var time = require("time"),
    i, now;

console.time("native");
for(i = 1000; i--; ) {
  now = new Date(1365187331709);
  now.setHours(0);
  now.setMinutes(0);
  now.setSeconds(0);
  now.setMilliseconds(0);
}
console.timeEnd("native");

console.time("time");
for(i = 1000; i--; ) {
  now = new time.Date(1365187331709);
  now.setTimezone("America/New_York");
  now.setHours(0);
  now.setMinutes(0);
  now.setSeconds(0);
  now.setMilliseconds(0);
}
console.timeEnd("time");

console.time("time w/ tz");
for(i = 1000; i--; ) {
  now = new time.Date(1365187331709);
  now.setTimezone("America/Chicago");
  now.setHours(0);
  now.setMinutes(0);
  now.setSeconds(0);
  now.setMilliseconds(0);
}
console.timeEnd("time w/ tz");

Error "node_modules/time/node_modules/nan" on npm install time

yesterday I was installing time without problems, today I get this error:

>npm install time
npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug

> [email protected] install /my_api/node_modules/time
> node-gyp rebuild

>make: Entering directory `/my_api/node_modules/time/build'
  CXX(target) Release/obj.target/time/src/time.o
g++: error: /my_api/node_modules/time/node_modules/nan: No such file or directory
make: *** [Release/obj.target/time/src/time.o] Error 1
make: Leaving directory `/my_api/node_modules/time/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.5.0-43-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /my_api/node_modules/time
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
npm ERR! weird error 1
npm ERR! not ok code 0

I am on [email protected]. Any ideas whats wrong?

Performance Issues

Setting a timezone and performing manipulations seems to have a massive performance impact. Is this to be expected or can optimizations be made?

var count =  10000

var start = (new Date).getTime()

for (var i = 1; i <= count; i ++) {
  var d = new Date
  d.setDate(20)
}

var end = (new Date).getTime()

console.log((end - start)/1000 + ' seconds')

Returns 0.026 seconds

var time  = require('time')
var count = 10000

var start = (new Date).getTime()

for (var i = 1; i <= count; i ++) {
  var d = new time.Date
  d.setTimezone('America/Montreal')
  d.setDate(20)
}

var end = (new Date).getTime()

console.log((end - start)/1000 + ' seconds')

Returns 9.718 seconds

Running version 0.8.3 against Node version 0.6.14 on Ubuntu Server 12.04LTS 32bit.

Inconsistent month values with different timezone

new time.Date(2013, 1, 1, 'Europe/Paris');

{ Thu, 31 Jan 2013 23:00:00 GMT
  getTimezone: [Function: getTimezone],
  getDate: [Function: getDate],
  getDay: [Function: getDay],
....
}

All is OK.

new time.Date(2013, 1, 1, 'America/New_York');

{ Fri, 01 Mar 2013 05:00:00 GMT
  getTimezone: [Function: getTimezone],
  getDate: [Function: getDate],
  getDay: [Function: getDay],
....
}

Wrong month...

install failed on (Ubuntu/Linaro 4.6.3-1ubuntu4)

Hi all,
I run the 'sudo npm install time' and return following error message, any idea and suggestion? thanks in advance!

B.R
Nick Lee

$ uname -a
Linux hotspot-dev-box 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux
$ node --version
v0.11.11
$ npm --version
1.3.25

LOG:

npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/debug

> [email protected] install /home/vagrant/workspace/countly-server/api/node_modules/time
> node-gyp rebuild

make: Entering directory `/home/vagrant/workspace/countly-server/api/node_modules/time/build'
  CXX(target) Release/obj.target/time/src/time.o
In file included from /usr/include/i386-linux-gnu/sys/socket.h:40:0,
                 from /home/vagrant/.node-gyp/0.11.11/deps/uv/include/uv-unix.h:29,
                 from /home/vagrant/.node-gyp/0.11.11/deps/uv/include/uv.h:60,
                 from /home/vagrant/workspace/countly-server/api/node_modules/time/node_modules/nan/nan.h:9
6,
                 from ../src/time.cc:7:
/usr/include/i386-linux-gnu/bits/socket.h:352:3: error: 'uid_t' does not name a type
/usr/include/i386-linux-gnu/bits/socket.h:353:3: error: 'gid_t' does not name a type
In file included from /home/vagrant/.node-gyp/0.11.11/deps/uv/include/uv-unix.h:31:0,
                 from /home/vagrant/.node-gyp/0.11.11/deps/uv/include/uv.h:60,
                 from /home/vagrant/workspace/countly-server/api/node_modules/time/node_modules/nan/nan.h:9
6,
                 from ../src/time.cc:7:
/usr/include/netinet/tcp.h:94:5: error: 'u_int16_t' does not name a type
/usr/include/netinet/tcp.h:95:5: error: 'u_int16_t' does not name a type
/usr/include/netinet/tcp.h:96:5: error: 'u_int32_t' does not name a type
/usr/include/netinet/tcp.h:97:5: error: 'u_int32_t' does not name a type
/usr/include/netinet/tcp.h:99:5: error: 'u_int16_t' does not name a type
/usr/include/netinet/tcp.h:100:5: error: 'u_int16_t' does not name a type

.
.
.

vagrant@hotspot-dev-box:~/workspace/countly-server/api$
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:107:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:879:12)
gyp ERR! System Linux 3.2.0-23-generic-pae
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/vagrant/workspace/countly-server/api/node_modules/time
gyp ERR! node -v v0.11.11
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-23-generic-pae
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "[email protected]"
npm ERR! cwd /home/vagrant/workspace/countly-server/api
npm ERR! node -v v0.11.11
npm ERR! npm -v 1.3.25
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/vagrant/workspace/countly-server/api/npm-debug.log
npm ERR! not ok code 0
vagrant@hotspot-dev-box:~/workspace/countly-server/api$
vagrant@hotspot-dev-box:~/workspace/countly-server/api$ node --version
v0.11.11
vagrant@hotspot-dev-box:~/workspace/countly-server/api$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

time.cc won't compile on osX maverick

Any idea on how to get this compiled? so far I'm getting headder errors saying the compiler can't find node.h, v8.h.. is there a way to do this manually where these include files are in non-standard locations?? It looks like node-gyp is not behaving well..

Won't link against binary Node on OS X

I just reproduced this on mine and @TooTallNate macs.

Instructions

  1. Install node-v0.6.11.pkg
  2. Clone node-time at ec3b2f8 (current HEAD)
  3. npm install
  4. npm test

Expected output

…
✔ 24 tests complete (35ms)

Obtained

> [email protected] test /Users/guillermorauch/Projects/node-time
> mocha --reporter spec

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Unable to load shared library /Users/guillermorauch/Projects/node-time/build/Release/time.node
    at Object..node (module.js:472:11)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at bindings (/Users/guillermorauch/Projects/node-time/node_modules/bindings/bindings.js:72:15)
    at Object.<anonymous> (/Users/guillermorauch/Projects/node-time/index.js:9:34)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/Users/guillermorauch/Projects/node-time/test/date.js:2:12)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at /Users/guillermorauch/Projects/node-time/node_modules/mocha/bin/_mocha:240:27
    at Array.forEach (native)
    at load (/Users/guillermorauch/Projects/node-time/node_modules/mocha/bin/_mocha:237:9)
    at Object.<anonymous> (/Users/guillermorauch/Projects/node-time/node_modules/mocha/bin/_mocha:228:1)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

npm ERR! [email protected] test: `mocha --reporter spec`
npm ERR! `sh "-c" "mocha --reporter spec"` failed with 1
npm ERR! 
npm ERR! Failed at the [email protected] test script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mocha --reporter spec
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.
npm ERR! 
npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "test"
npm ERR! cwd /Users/guillermorauch/Projects/node-time
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] test: `mocha --reporter spec`
npm ERR! message `sh "-c" "mocha --reporter spec"` failed with 1
npm ERR! errno {}
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/guillermorauch/Projects/node-time/npm-debug.log

Install Issues on OSX

I'm having trouble installing time on my Mac, seems to install on Linux however. Python version is 2.7.2.

$ npm install time

> [email protected] install /Users/tyler/projects/prescribed/node_modules/time
> node-gyp rebuild

  CXX(target) Release/obj.target/time/src/time.o
make: c++: No such file or directory
make: *** [Release/obj.target/time/src/time.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:219:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:91:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:674:10)
gyp ERR! System Darwin 12.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/tyler/projects/prescribed/node_modules/time
gyp ERR! node -v v0.8.1
gyp ERR! node-gyp -v v0.6.6
gyp ERR! not ok 
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "time"
npm ERR! cwd /Users/tyler/projects/prescribed
npm ERR! node -v v0.8.1
npm ERR! npm -v 1.1.51
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/tyler/projects/prescribed/npm-debug.log
npm ERR! not ok code 0

Thanks for your help!

Windows error during installation

..\src\time.cc(32): warning C4244: 'argument' : conversion from 'time_t' to 'in
t32_t', possible loss of data [c:\ProjetsHTML\myProject\node_modules\time\build
\time.vcxproj]
..\src\time.cc(124): warning C4244: 'argument' : conversion from 'time_t' to 'i
nt32_t', possible loss of data [c:\ProjetsHTML\myProject\node_modules\time\buil
d\time.vcxproj]
C:\Users\julie.cardinal.node-gyp\0.10.0\deps\v8\include\v8.h(184): warning C45
06: no definition for inline function 'v8::Persistent v8::Persistent::New
(v8::Handle)' [c:\ProjetsHTML\myProject\node_modules\nodetime\node_modules\n
odetime-native\build\nodetime_native.vcxproj]
with

T=v8::Object

nodetime_native.cc
C:\Users\julie.cardinal.node-gyp\0.10.0\deps\v8\include\v8.h(184): warning C45
06: no definition for inline function 'v8::Persistent v8::Persistent::New
(v8::Handle)' [c:\ProjetsHTML\myProject\node_modules\time\build\time.vcxproj
]
with
[
T=v8::Object
]
C:\Users\julie.cardinal.node-gyp\0.10.0\deps\v8\include\v8.h(184): warning C45
06: no definition for inline function 'v8::Persistent v8::Persistent::New
(v8::Handle)' [c:\ProjetsHTML\myProject\node_modules\nodetime\node_modules\n
odetime-native\build\nodetime_native.vcxproj]
with

T=v8::Object

Creating library c:\ProjetsHTML\myProject\node_modules\time\build\Release
time.lib and object c:\ProjetsHTML\myProject\node_modules\time\build\Release
time.exp
Generating code

Doesn't install on iojs (OSX)

$ npm install time
-
> [email protected] install /Users/medikoo/Projects/_tests/time/node_modules/time
> node-gyp rebuild

child_process: customFds option is deprecated, use stdio instead.
  CXX(target) Release/obj.target/time/src/time.o
In file included from ../src/time.cc:7:
../node_modules/nan/nan.h:616:19: error: no type named 'ExternalAsciiStringResource' in 'v8::String'; did you mean 'ExternalStringResource'?
      v8::String::ExternalAsciiStringResource *resource) {
      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
                  ExternalStringResource
/Users/medikoo/.node-gyp/1.0.3/deps/v8/include/v8.h:2016:19: note: 'ExternalStringResource' declared here
  class V8_EXPORT ExternalStringResource
                  ^
In file included from ../src/time.cc:7:
../node_modules/nan/nan.h:615:36: error: redefinition of 'NanNew'
  NAN_INLINE v8::Local<v8::String> NanNew(
                                   ^
../node_modules/nan/nan.h:610:36: note: previous definition is here
  NAN_INLINE v8::Local<v8::String> NanNew(
                                   ^
../node_modules/nan/nan.h:1973:12: error: no member named 'IsExternalAscii' in 'v8::String'; did you mean 'IsExternal'?
  if (str->IsExternalAscii()) {
           ^~~~~~~~~~~~~~~
           IsExternal
/Users/medikoo/.node-gyp/1.0.3/deps/v8/include/v8.h:1980:8: note: 'IsExternal' declared here
  bool IsExternal() const;
       ^
In file included from ../src/time.cc:7:
../node_modules/nan/nan.h:1974:23: error: no type named 'ExternalAsciiStringResource' in 'v8::String'; did you mean 'ExternalStringResource'?
    const v8::String::ExternalAsciiStringResource* ext;
          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
                      ExternalStringResource
/Users/medikoo/.node-gyp/1.0.3/deps/v8/include/v8.h:2016:19: note: 'ExternalStringResource' declared here
  class V8_EXPORT ExternalStringResource
                  ^
In file included from ../src/time.cc:7:
../node_modules/nan/nan.h:1975:16: error: no member named 'GetExternalAsciiStringResource' in 'v8::String'; did you mean 'GetExternalOneByteStringResource'?
    ext = str->GetExternalAsciiStringResource();
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               GetExternalOneByteStringResource
/Users/medikoo/.node-gyp/1.0.3/deps/v8/include/v8.h:2083:40: note: 'GetExternalOneByteStringResource' declared here
  const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
                                       ^
In file included from ../src/time.cc:7:
../node_modules/nan/nan.h:1975:9: error: assigning to 'const v8::String::ExternalStringResource *' from incompatible type 'const v8::String::ExternalOneByteStringResource *'
    ext = str->GetExternalAsciiStringResource();
        ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/nan/nan.h:1976:11: error: assigning to 'const char *' from incompatible type 'const uint16_t *' (aka 'const unsigned short *')
    *data = ext->data();
          ^ ~~~~~~~~~~~
7 errors generated.
make: *** [Release/obj.target/time/src/time.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/medikoo/.nvm/versions/io.js/v1.0.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1038:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/Users/medikoo/.nvm/versions/io.js/v1.0.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/medikoo/Projects/_tests/time/node_modules/time
gyp ERR! node -v v1.0.3
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok 
npm ERR! Darwin 14.0.0
npm ERR! argv "/Users/medikoo/.nvm/versions/io.js/v1.0.3/bin/iojs" "/Users/medikoo/.nvm/versions/io.js/v1.0.3/bin/npm" "install" "time"
npm ERR! node v1.0.3
npm ERR! npm  v2.2.0
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/medikoo/Projects/_tests/time/npm-debug.log

Raspberry Pi unable to run module

Curious if I should continue to try and get this to run on my raspberry pi. Code runs fine on my mac, but on my raspberry pi (raspian distro) which runs node like a champ, this libe will give me the following error:

/opt/cbus/node_modules/time/node_modules/bindings/bindings.js:79
throw e
^
Error: Unable to load shared library /opt/cbus/node_modules/time/build/Release/time.node
at Object..node (module.js:477:11)
at Module.load (module.js:353:32)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at bindings (/opt/cbus/node_modules/time/node_modules/bindings/bindings.js:74:15)
at Object. (/opt/cbus/node_modules/time/index.js:9:35)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:32)

"Unknown Timezone" thrown for UTC+0 timezones (WET, Etc/GMT, GMT0...)

There are several countries in Africa that use the GMT0 timezone. This is the UTC+0.

However, I found no way to set up this timezone using nodetime. All of these attempts fail:

GMT-0, GMT+0, UTC, Etc/GMT, WET...

It's also the Western European Time (WET). The strange thing is that it works for Portugal (Europe/Lisbon) when I set the Daylight Saving Time like this:

"WET0WEST,M3.5.0/1,M10.5.0",

But not if I set only "WET0" or "WET" for the African countries without the summer time switching.

Any tips on what could be the reason? where does nodetime obtain the timezone values from? could be that since UTC +0 is the reference time it's not considered a valid timezone by node-time?

In my Linux system, when I run "TZ=UTC date" it shows the time properly in the UTC+0 timezone, it also works if I use "TZ=GMT0 date", but not with ' node <<< require("time").Date().setTimezone("GMT0"); '.

How would I use node-time to load a UTC+0 timezone?

npm install time - not working

Hi,

I appear to be getting this error when I try npm install time. I've also tried installing as root user but no luck.

Chris

gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16
gyp ERR! stack at Object.oncomplete (fs.js:297:15)
gyp ERR! System Darwin 12.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/ttrojan/node_modules/time
gyp ERR! node -v v0.8.4
gyp ERR! node-gyp -v v0.6.1
gyp ERR! not ok
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! sh "-c" "node-gyp rebuild" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the time package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls time
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "time"
npm ERR! cwd /Users/user
npm ERR! node -v v0.8.4
npm ERR! npm -v 1.1.45
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/ttrojan/npm-debug.log
npm ERR! not ok code 0

Parsing a time string in a given timezone

@TooTallNate: Great library! I really want to use it to replace the crazy hack job I have done without it.. but I can't seem to find a way to parse a time in a given timezone.

For instance, my process.env.TZ = 'UTC'..
but I want to take a user's input as "Jan 16, 2010 20:16" as America/New York..

Date.parse requires that I append "EST" to the end of the string etc.. but I can't find a good way to go from "America/New York" to EST/EDT because we then need to determine if it's daylight savings time, etc.. There must be a better way. What am I missing??

Thanks!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.