npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moment-calendarday

v0.0.7

Published

A moment.js plugin which allows to config and access calendar day information.

Downloads

15

Readme

MIT License

Typescript Calendar class implemented as a moment.js plugin. This is a alpha version - Do not use it until I release version 1.0.0

Open issues before V 1.0.0

  • [x] make the code work in the browser
  • [ ] make the code work in node
  • [ ] Travis build
  • [ ] Code coverage
  • [ ] Project badges
  • [ ] Semantic versioning
  • [ ] V 1.0.0

What is it?

A Typescript Calendar class implemented as a moment.js plugin which allows to config and access calendar day information.

I wanted to name the plugin moment-calender, a name which is already taken. Therefor I had to change the name to moment-calendarday. This project is the successor of the project calendar-standalone. Any further development will be done in this project.

Getting it

In the browser

Just link to both moment.js and moment-calendarday.js:

<script src="node_modules/moment/moment.js"></script>
<script src="node_modules/moment-calendarday/lib/web/moment-calendarday.js"></script>

In node

Just require moment-calendarday:

var moment = require('moment-calendarday');

Configuration

A calendar day is described with the class CalenderDayEntry. Currently it has just two properties:

  • name, the name of the day
  • isFeastDay, a boolean property which defines if the day is a feast day

The initialisation of a calendar year is done with a JSON structure, defined in ConfigDays, as follows:

var config = { /* REST structure */ };
moment.initCalendarDays(config);

The advantage of the given implementation is that the config is year independent, so there is no need to adapt the config every year. The main structure is:

/** root structure */
export interface ConfigDays {
	configFixedDays?                    : ConfigFixedDay[];
	configEasterDependantDays?          : ConfigEasterDependantDay[];
	configNthWeekdayInMonthDays?        : ConfigNthWeekdayInMonthDay[];
	configNthWeekdayRelativeToDateDays? : ConfigNthWeekdayRelativeToDateDay[];
}

Fixed days are days which occure every year on the same date (like 24.12. when no year is given) or even days at aspecific date (only 24.12.1015 and not the 24.12. on every year):

export interface ConfigFixedDay {
	day         : number;       // day
	month       : number;       // month
	year?       : number;       // year (when given, the entry defines a concrete date)
	name        : string;       // Name of the day
	isFeastDay  : boolean;      // Is the day a feast day?
}

Easter dependant days are days which are calculated relative to the Easter Sunday, like the Easter Sunday itself or the Palm Sunday.

export interface ConfigEasterDependantDay {
	delta       : number;       // Number of days relative to the Easter Sunday
	name        : string;       // Name of the day
	isFeastDay  : boolean;      // Is the day a feast day?
}

You can also define days occurring on the Nth Weekday of a month . This is needed e.g. for Mothers and Fathers Day.

export interface ConfigNthWeekdayInMonthDay {
	weekCount   : number;       // count of the weekday (N)
	weekday     : Weekday;      // Weekday
	month       : number;       // month
	name        : string;       // Name of the day
	isFeastDay  : boolean;      // Is the day a feast day?
}

And finally you can define days occurring relative to a given date. This is needed e.g. for the Advent sundays.

export interface ConfigNthWeekdayRelativeToDateDay {
	day         : number;       // reference date, day
	month       : number;       // reference date, month
	weekCount   : number;       // count of the weekday (N)
	weekday     : Weekday;      // Weekday
	name        : string;       // Name of the day
	isFeastDay  : boolean;      // Is the day a feast day?
}

A configuration which uses one entry of every option above looks like

var config = {
	configFixedDays : [{
			"day"           : 1,
			"month"         : 1,
			"name"          : "New Year",
			"isFeastDay"    : true
		}],
	configEasterDependantDays : [{
			"delta"         : 0,
			"name"          : "Easter Sunday",
			"isFeastDay"    : true
		}],
	configNthWeekdayInMonthDays : [{
			"weekCount"     : 2,
			"weekday"       : 7,
			"month"         : 5,
			"name"          : "Mother's day",
			"isFeastDay"    : false
		}],
	configNthWeekdayRelativeToDateDays : [{
			"day"           : 25,
			"month"         : 12,
			"weekCount"     : -4,
			"weekday"       : 7,
			"name"          : "1. Advent",
			"isFeastDay"    : false
		}]
};
moment.initCalendarDays(config);

As you can see the configuration doesn't use the standard moment.js scheme (month from 0 to 11, week start is Sunday with value 0, Monday=1, ...). Instead it uses the European format (month from 1 to 12, week start is Monday with value 1, Sunday=7). For other config examples have a look at the unit tests test/*ConfigSpec.ts

Usage

With the example configuration above you will get for any year's value:

var result = moment().date(1).month(0).year(2015);
expect(result.dayName()).toBe("New Year");
expect(result.isFeastDay()).toBeTruthy();

result = moment().date(5).month(3).year(2015);
expect(result.dayName()).toBe("Easter Sunday");
expect(result.isFeastDay()).toBeTruthy();

result = moment().date(10).month(4).year(2015);
expect(result.dayName()).toBe("Mother's day");
expect(result.isFeastDay()).toBeTruthy();

result = moment().date(29).month(10).year(2015);
expect(result.dayName()).toBe("1. Advent");
expect(result.isFeastDay()).toBeFalsy();