Installations
npm install time
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
7.6.0
NPM Version
4.1.2
Score
67.3
Supply Chain
98.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (83.68%)
C++ (14.86%)
Python (1.45%)
Developer
TooTallNate
Download Statistics
Total Downloads
2,122,650
Last Day
50
Last Week
482
Last Month
2,422
Last Year
26,693
GitHub Statistics
382 Stars
277 Commits
83 Forks
19 Watching
2 Branches
14 Contributors
Package Meta Information
Latest Version
0.12.0
Package Id
time@0.12.0
Size
14.53 kB
NPM Version
4.1.2
Node Version
7.6.0
Total Downloads
Cumulative downloads
Total Downloads
2,122,650
Last day
-77.9%
50
Compared to previous day
Last week
-23.7%
482
Compared to previous week
Last month
39.5%
2,422
Compared to previous month
Last year
-53.5%
26,693
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
node-time
"time.h" bindings for Node.js.
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:
1$ npm install time
Example
1var time = require('time'); 2 3// Create a new Date instance, representing the current instant in time 4var now = new time.Date(); 5 6now.setTimezone("America/Los_Angeles"); 7// `.getDate()`, `.getDay()`, `.getHours()`, etc. 8// will return values according to UTC-8 9 10now.setTimezone("America/New_York"); 11// `.getDate()`, `.getDay()`, `.getHours()`, etc. 12// will return values according to UTC-5 13 14 15// You can also set the timezone during instantiation 16var azDate = new time.Date(2010, 0, 1, 'America/Phoenix'); 17azDate.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:
1var time = require('time')(Date); 2 3var d = new Date(); 4d.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.
1var now = new time.Date(); 2var another = new time.Date('Aug 9, 1995', 'UTC'); 3var 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.
1date.setTimezone("America/Argentina/San_Juan") 2 3// Default behavior: 4a = new time.Date() 5a.toString() 6// 'Wed Aug 31 2011 09:45:31 GMT-0700 (PDT)' 7a.setTimezone('UTC') 8a.toString() 9// 'Wed Aug 31 2011 16:45:31 GMT+0000 (UTC)' 10 11// Relative behavior: 12b = new time.Date() 13b.toString() 14// 'Wed Aug 31 2011 10:48:03 GMT-0700 (PDT)' 15b.setTimezone('UTC', true) 16b.toString() 17// '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.
1date.getTimezone(); 2 // "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.
1date.getTimezoneAbbr(); 2 // "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()
.
1time.Date.parse("1970, January 1"); // <- Local Time 2 // 28800000 3time.Date.parse("1970, January 1", "Europe/Copenhagen"); 4 // -3600000 5time.Date.parse("1970, January 1", "UTC"); 6 // 0
extend(date) -> Date
Transforms a "regular" Date instance into one of node-time
's "extended" Date instances.
1var d = new Date(); 2// `d.setTimezone()` does not exist... 3time.extend(d); 4d.setTimezone("UTC");
time() -> Number
Binding for time()
. Returns the number of seconds since Jan 1, 1900 UTC.
These two are equivalent:
1time.time(); 2 // 1299827226 3Math.floor(Date.now() / 1000); 4 // 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.
1time.tzset('US/Pacific'); 2 // { tzname: [ 'PST', 'PDT' ], 3 // timezone: 28800, 4 // 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()
).
1time.localtime(Date.now()/1000); 2 // { seconds: 38, 3 // minutes: 7, 4 // hours: 23, 5 // dayOfMonth: 10, 6 // month: 2, 7 // year: 111, 8 // dayOfWeek: 4, 9 // dayOfYear: 68, 10 // isDaylightSavings: false, 11 // gmtOffset: -28800, 12 // 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...
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 5/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More