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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wt-date-utils

v1.0.0

Published

Word Tutor 日期处理工具库,支持北京时间2AM日期分界规则

Downloads

84

Readme

wt-date-utils

Word Tutor 日期处理工具库,支持北京时间 2AM 日期分界规则。

安装

npm install wt-date-utils

核心规则

  • 时区:北京时间(UTC+8)
  • 日期分界线:北京时间凌晨 02:00(对应 UTC 18:00)
  • 分界规则
    • 北京时间 00:00-01:59:59 算作前一天
    • 北京时间 02:00-23:59:59 算作当天

使用示例

const DateUtils = require('wt-date-utils');

// 获取学习日期
const learnDate = DateUtils.getLearnDate('2025-01-05T17:30:00.000Z');
// 北京时间 01:30 → 返回 '2025-01-05'(算作前一天)

const learnDate2 = DateUtils.getLearnDate('2025-01-05T18:30:00.000Z');
// 北京时间 02:30 → 返回 '2025-01-06'(算作当天)

// 计算复习日期
const reviewDates = DateUtils.calculateReviewDates('2025-01-05', [1, 2, 4, 7]);
// 返回 ['2025-01-06', '2025-01-07', '2025-01-09', '2025-01-12']

// 获取学习日期的 UTC 时间范围
const range = DateUtils.getLearnDateUTCRange('2025-01-05');
// range.start = UTC 2025-01-04 18:00:00.000
// range.end = UTC 2025-01-05 17:59:59.999

// 检查时间是否属于某个学习日期
const isInRange = DateUtils.isInLearnDateRange('2025-01-05T10:00:00.000Z', '2025-01-05');
// 返回 true

API 文档

常量

  • BEIJING_OFFSET_MS - 北京时间偏移量(毫秒),值为 8 * 60 * 60 * 1000
  • BOUNDARY_HOUR - 日期分界小时,值为 2

函数

toBeijingTime(utcTime)

将 UTC 时间转换为北京时间。

  • 参数: utcTime - Date 对象、ISO 字符串或时间戳
  • 返回: Date 对象(北京时间),无效输入返回 Invalid Date

getNowBeijing()

获取当前北京时间。

  • 返回: Date 对象(当前北京时间)

getLearnDate(utcTime)

根据 2AM 分界规则,从时间戳计算学习日期。

  • 参数: utcTime - UTC 时间戳
  • 返回: 学习日期字符串 YYYY-MM-DD,无效输入返回空字符串

isInLearnDateRange(utcTime, learnDate)

检查时间戳是否属于指定学习日期。

  • 参数:
    • utcTime - UTC 时间戳
    • learnDate - 学习日期 YYYY-MM-DD
  • 返回: boolean

getLearnDateUTCRange(learnDate)

获取学习日期对应的 UTC 时间范围。

  • 参数: learnDate - 学习日期 YYYY-MM-DD
  • 返回: { start: Date, end: Date } UTC 时间范围

calculateReviewDates(learnDate, reviewPlan)

计算复习日期数组。

  • 参数:
    • learnDate - 学习日期 YYYY-MM-DD
    • reviewPlan - 复习计划天数数组,如 [1, 2, 4, 7]
  • 返回: 复习日期数组,无效输入返回空数组

formatDateOnly(date)

格式化日期为 YYYY-MM-DD 字符串。

  • 参数: date - Date 对象
  • 返回: 格式化的日期字符串,无效输入返回空字符串

parseDateString(dateStr)

解析 YYYY-MM-DD 字符串为 Date 对象(UTC 0点)。

  • 参数: dateStr - 日期字符串
  • 返回: Date 对象,无效输入返回 Invalid Date

calculateReviewIndex(learnTime, reviewDate, reviewPlan)

计算复习索引。

  • 参数:
    • learnTime - 学习时间
    • reviewDate - 复习日期 YYYY-MM-DD
    • reviewPlan - 复习计划数组
  • 返回: 复习索引,未找到返回 -1

时间范围说明

UTC 时间轴:
    |-------|-------|-------|-------|-------|-------|
   12:00   14:00   16:00   18:00   20:00   22:00   00:00
    
北京时间轴 (UTC+8):
    |-------|-------|-------|-------|-------|-------|
   20:00   22:00   00:00   02:00   04:00   06:00   08:00
                     ↑       ↑
                  前一天   当天开始
                  结束     (分界线)

License

MIT