calendar

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package calendar defines the Shanghai civil-date rules shared by Life@USTC clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDate

func ParseDate(value string) (time.Time, error)

ParseDate parses a canonical YYYY-MM-DD date in Asia/Shanghai.

func ShanghaiDate

func ShanghaiDate(at time.Time) string

ShanghaiDate converts an instant to its Shanghai calendar date.

func TeachingWeekNumber added in v0.2.0

func TeachingWeekNumber(semesterStart, selectedDate string, firstWeekday time.Weekday) (int, error)

TeachingWeekNumber returns the week containing selectedDate, counting the week containing semesterStart as one. Earlier weeks have zero/negative numbers; the caller decides whether that week belongs to the semester.

Types

type DateRange

type DateRange struct {
	From string `json:"from"`
	To   string `json:"to"`
}

DateRange contains inclusive Shanghai calendar dates.

func Bounds

func Bounds(period Period, anchor time.Time, firstWeekday time.Weekday) (DateRange, error)

Bounds returns the complete day, week or month containing anchor. firstWeekday is explicit because public and personal calendars differ.

func RequestWindows

func RequestWindows(from, to string) ([]DateRange, error)

RequestWindows divides an inclusive range into adjacent windows of at most 366 days.

func TeachingWeekBounds added in v0.2.0

func TeachingWeekBounds(semesterStart string, weekIndex int, firstWeekday time.Weekday) (DateRange, error)

TeachingWeekBounds returns the complete week at a one-based teaching-week index. Week one contains semesterStart; callers retain semester clipping.

type Period

type Period string
const (
	Day   Period = "day"
	Week  Period = "week"
	Month Period = "month"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL