Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

time

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

time - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

140

index.js
var bindings = require('./time');
exports.time = bindings.time;
exports.tzset = bindings.tzset;
exports.localtime = bindings.localtime;
// The user-facing 'tzset' function accepts a timezone String
// to set to, and returns an object with the zoneinfo for the
// timezone.
function tzset(tz) {
if (tz) {
process.env.TZ = tz;
}
var usedTz = process.env.TZ;
var rtn = bindings.tzset();
if (!rtn.tzname[1] && rtn.timezone === 0) {
var err = new Error("Unknown Timezone: '" + usedTz + "'");
for (var i in rtn) {
err[i] = rtn[i];
}
throw err;
}
return rtn;
}
exports.tzset = tzset;
var DateProto = global.Date.prototype;

@@ -14,100 +33,55 @@

function setTimeZone(timezone) {
var oldTz = process.env.TZ;
tzset(timezone);
this._timezone = timezone;
if (!('_getEpochSeconds' in this)) extend(this, extensions);
var origTz = process.env.TZ;
process.env.TZ = timezone;
bindings.tzset();
this._zoneInfo = bindings.localtime(this._getEpochSeconds());
process.env.TZ = origTz;
bindings.tzset();
return this._zoneInfo;
}
DateProto.setTimeZone = setTimeZone;
var zoneInfo = bindings.localtime(this / 1000);
if (oldTz) {
tzset(oldTz);
}
// If we got to here without throwing an Error, then
// a valid timezone was requested, and we should have
// a valid zoneInfo Object.
// Returns a "String" of the last value set in "setTimeZone".
function getTimeZone() {
return this._timezone;
}
DateProto.getTimeZone = getTimeZone;
// These props gets monkey-patched onto a Date instance after the first time
// the 'setTimeZone()' function is called on that instance.
var extensions = {
// Like 'getTime', but returns seconds instead of milliseconds
_getEpochSeconds: function getEpochSeconds() {
return Math.floor(this.getTime() / 1000);
},
//
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
//
// Returns the day of the month (1-31) for the specified date according to local time.
getDate: function getDate() {
return '_zoneInfo' in this ?
this._zoneInfo.dayOfMonth :
DateProto.getDate.call(this);
},
this.getDate = function getDate() {
return zoneInfo.dayOfMonth;
}
// Returns the day of the week (0-6) for the specified date according to local time.
getDay: function getDay() {
return '_zoneInfo' in this ?
this._zoneInfo.dayOfWeek :
DateProto.getDay.call(this);
},
this.getDay = function getDay() {
return zoneInfo.dayOfWeek;
}
// Deprecated. Returns the year (usually 2-3 digits) in the specified date according
// to local time. Use `getFullYear()` instead.
getYear: function getYear() {
return '_zoneInfo' in this ?
this._zoneInfo.year:
DateProto.getYear.call(this);
},
this.getYear = function getYear() {
return zoneInfo.year;
}
// Returns the year (4 digits for 4-digit years) of the specified date according to local time.
getFullYear: function getFullYear() {
return '_zoneInfo' in this ?
this._zoneInfo.year + 1900:
DateProto.getFullYear.call(this);
},
this.getFullYear = function getFullYear() {
return zoneInfo.year + 1900;
}
// Returns the hour (0-23) in the specified date according to local time.
getHours: function getHours() {
return '_zoneInfo' in this ?
this._zoneInfo.hours:
DateProto.getHours.call(this);
},
this.getHours = function getHours() {
return zoneInfo.hours;
}
// Returns the minutes (0-59) in the specified date according to local time.
getMinutes: function getMinutes() {
return '_zoneInfo' in this ?
this._zoneInfo.minutes:
DateProto.getMinutes.call(this);
},
this.getMinutes = function getMinutes() {
return zoneInfo.minutes;
}
// Returns the month (0-11) in the specified date according to local time.
getMonth: function getMonth() {
return '_zoneInfo' in this ?
this._zoneInfo.month:
DateProto.getMonth.call(this);
},
this.getMonth = function getMonth() {
return zoneInfo.month;
}
// Returns the seconds (0-59) in the specified date according to local time.
getSeconds: function getSeconds() {
return '_zoneInfo' in this ?
this._zoneInfo.seconds:
DateProto.getSeconds.call(this);
this.getSeconds = function getSeconds() {
return zoneInfo.seconds;
}
}
DateProto.setTimeZone = setTimeZone;
function extend(dest, source) {
for (var prop in source) {
dest[prop] = source[prop];
}
// Returns a "String" of the last value set in "setTimeZone".
function getTimeZone() {
return this._timezone;
}
DateProto.getTimeZone = getTimeZone;
{
"name": "time",
"description": "\"time.h\" bindings for NodeJS",
"version": "0.0.1",
"version": "0.0.2",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc