Skip to content

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

License

Notifications You must be signed in to change notification settings

es-shims/Date.prototype.getYear

Repository files navigation

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

About

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

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks