Socket
Book a DemoInstallSign in
Socket

date.prototype.getyear

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date.prototype.getyear

An ES5 spec-compliant `Date.prototype.getYear` shim/polyfill/replacement that works as far down as ES3.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

date.prototype.getyear Version Badge

github actions coverage License Downloads

npm badge

An ES spec-compliant Date.prototype.getYear shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Because Date.prototype.getYear depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument.

Example

var getYear = require('date.prototype.getyear');
var assert = require('assert');

var d = new Date(Date.UTC(2000));
d.setHours(d.getHours() + (d.getTimezoneOffset() / 60)); // to account for the local TZ

assert.equal(getYear(d), 100);
var shim = require('date.prototype.getyear/shim');
var getPolyfill = require('date.prototype.getyear/polyfill');
var assert = require('assert');
/* when Date#getYear is not present */
delete Date.prototype.getYear;
var shimmed = shim();
assert.equal(shimmed, getPolyfill());
assert.equal(shimmed, Date.prototype.getYear);
assert.equal(new Date().getYear(), getYear(new Date()));
var shim = require('date.prototype.getyear/shim');
var assert = require('assert');
/* when Date#getYear is present */
var shimmed = shim();
assert.equal(shimmed, Date.prototype.getYear);
assert.equal(new Date().getYear(), getYear(new Date()));

Tests

Simply clone the repo, npm install, and run npm test

Keywords

ecmascript

FAQs

Package last updated on 04 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts