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

h-calendar

v1.0.0

Published

The first bae nodejs app!

Downloads

4

Readme

基本用法


	//---实例化对象
	import Calendar from 'calendar';
	let calendar = new Calendar(new Date(),"+8:00");

	//---无参数,默认使用当前时间;
	import Calendar from 'calendar';
	let calendar = new Calendar();

方法


  • setDate(date) : 设置日历日期;
  • getDate() : 返回month加1后的日历日期对象
	let date = calendar.getDate();
	console.log(date);

	{
		props:{year,month,day,hours,minute,second}, //---对象形式
		spread:[year,month,day,hours,minute,second], //---数组形式
		date: date //--日期对象
	}
  • prevDate(num) : 获取num月前的日期对象
  • nextDate(num) : 获取num月后的日期对象
  • setTimezone(str) : 设置时区 "+8:00"; "-8:00";
  • getTimezone() : 返回时区;
  • cache() : 缓存当前日期数据
  • restore() : 恢复缓存的日期数据
	let date = calendar.prevDate(); //--获取上个月对象
	calendar.cache()  //---保存当前日期
	calendar.setDate(date);
	console.log(calendar.getDate())
	calendar.restore() //--恢复到之前的日期
	console.log(calendar.getDate());

  • now() : 当前时间戳
  • size() : 日历天数
  • week() : 当前日星期
  • firstWeek() : 日历的第一个星期
  • lastWeek() : 日历的最后一个星期
  • days(Boolean strict) : 返回按照以周为单位进行分割的二位数组;strict超出本月的日期是否返回实际的日期,默认返回0;内部数组的序列号对应的是week中的0-6;即:星期天-星期一
	let days = calendar.days();

	console.log(days);

	[
		[0,1,2,3,4,5,6],
		[7,8,9,10,11,12,13],
		[14,15,16,17,18,19,20],
		[21,22,23,24,25,26,27],
		[28,29,30,31,0,0,0],
	]

  • getRelativeDate(num,type) : 获取相对当前时间num(正向后,负向前)长度的日期对象;type包含"day","week","month","year";
	let date = calendar.getRelativeDate(1,'month');

	console.log(date);

	{
		props:{},
		spread:[],
		date : date

	}
  • getRelativeDates(num,type) : 获取相对当前时间num(正向后,负向前)长度的日期对象数组;type包含"day","week","month","year";
	let date = calendar.getRelativeDates(1,'month');

	console.log(date);

	[date1,date2,date3,date4,......];

  • getDiffByDate(date) : 获取两个日期的天数差;返回数据
	let date = calendar.getDiffByDate(1,'month');

	console.log(calendar.getDiffByDate(date.date));
	
	输出:31
  • transformTimezone(timezone) : 转化为timezone时区的日历;

  • format(str) : 返回str连接的时间字符串 "2016-05-08 21:00:00";

  • suffix(num) : 对小于10的数字加上前缀返回字符串:

	console.log(calendar.suffix(5)) // '05';