1.1.0 • Published 4 years ago

awesome-new-gunn-schedule-package v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

awesome-new-gunn-schedule-package

A Node package that gets Gunn's alternate schedules for you. It uses the Google Calendar API to obtain the up-to-date alternate schedules for Gunn High School according to the events on their website.

How do I use this for my own projects?

You'll need a Google Calendar API key so it can fetch from the school's Google Calendar to generate the events.

Using Node or Webpack:

npm install awesome-new-gunn-schedule-package --save
const GunnSchedule = require('awesome-new-gunn-schedule-package')
const { apiKey } = require('./api-key.json')

For the web:

<script src="https://unpkg.com/awesome-new-gunn-schedule-package@1/dist/awesome-new-gunn-schedule-package.min.js" charset="utf-8"></script>

Then in your magic JavaScript:

// 2020-2021 school year
const schedule = new GunnSchedule(apiKey)
const year = schedule.year('2020-08-17', '2021-06-03', {
  normalSchedule: GunnSchedule.schedule2021,
  calendarId: 'fg978mo762lqm6get2ubiab0mk0f6m2c@import.calendar.google.com',
  defaultSelf: 0b1111
})
await year.update()
console.log(year.get('2020-09-04').periods)

// 2019-2020 school year
const schedule = new GunnSchedule(apiKey)
const year = schedule.year('2019-08-13', '2020-06-04')
await year.update()
console.log(year.get('2019-11-21').periods)

Documentation

UTCDate

The package uses dates in UTC so time zones don't mess with things. Methods accepting "UTCDates" will accept milliseconds since the Unix Epoch at 00:00 UTC on the desired date or a string date in YYYY-MM-DD. Put simply, for any method that takes a "UTCDate," you can do one of the following:

someMethod(Date.UTC(2019, 6, 4))
someMethod('2019-07-04')

Summary

new GunnSchedule(apiKey: string)
  .apiKey: string
  .year(firstDay: UTCDate, lastDay: UTCDate, options?: YearOptions): SchoolYear
GunnSchedule.schedule1920: PeriodData[][]
GunnSchedule.schedule2021: PeriodData[][]
GunnSchedule.Periods: Object
GunnSchedule.normalSchedule(day: number): Period[]

SchoolYear
  .firstDay: number
  .lastDay: number
  .update(): Promise<void>
  .update(date: UTCDate): Promise<void>
  .update(startDay: UTCDate, endDay: UTCDate): Promise<void>
  .get(date: UTCDate): Day

Day
  .date: Date
  .day: number
  .periods: Period[]
  .school: boolean
  .alternate: boolean
  .summer: boolean
  .toJSON(): Object[]

Period
  .period: string
  .start: Time
  .end: Time
  .selfGrades: number[]
  .toJSON(): Object

Time
  .hour: number
  .minute: number
  .totalMinutes: number
  .toTime(militaryTime: boolean = false): string

GunnSchedule

Stores the API key and lets you create SchoolYear instances

Constructor

new GunnSchedule(apiKey: string)

apiKey: The Google Calendar API with which the Google Calendar events should be fetched for the alternate schedules.

Properties

.apiKey: string

The Google Calendar API key given in the constructor. You can change this if you want, and new requests made will use the new API key.

Methods

interface PeriodData {
  period: string
  start: number
  end: number
  selfGrades?: number
}
interface YearOptions {
  normalSchedule?: PeriodData[][]
  calendarId?: string
  defaultSelf?: number
  timeZone?: string
}

.year(firstDay: UTCDate, lastDay: UTCDate, options?: YearOptions): SchoolYear

Creates a SchoolYear with the specified dates as the first and last days of the school year. For compatibility reasons, it uses the 2019-2020 school year's normal schedule settings by default.

Static properties

.schedule1920: PeriodData[][]
.schedule2021: PeriodData[][]

The normal schedules for the 2019-2020 and 2020-2021 school years, respectively. These are made so you can insert them in GunnSchedule#year.

.Periods: Object

An object of constants which are used to identify periods. For example, GunnSchedule.Periods.A is the name used to identify A periods.

Static methods

.normalSchedule(day: number): Period[]

Returns an array of Periods for the normal schedule on the given day of the week (an integer between 0 and 6).

SchoolYear

Represents a school year and fetches, parses, and stores the alternate schedules during that year.

Properties

.firstDay: number
.lastDay: number

The first and last days as given in the constructor, converted to the number of milliseconds since the Unix Epoch.

Methods

.update(): Promise<void>

Fetches, parses, and stores/updates the alternate schedules (and SELF classes) for the entire school year.

.update(date: UTCDate): Promise<void>

Like above, but it only fetches the alternate schedules for the specified day.

.update(startDay: UTCDate, endDay: UTCDate): Promise<void>

Like above, but it fetches the alternate schedules in the range between the given dates.

.get(date: UTCDate): Day

Returns a new instance of Day with the schedule data of the specified day.

Day

Contains the schedule for the school day it represents.

Properties

.date: Date

The JavaScript Date object representing the school day's date in UTC; you can use UTC methods on this such as getUTCFullYear or getUTCDay.

.day: number

The day of the week of the school day in UTC (equivalent to dayInstance.date.getUTCDay()).

.periods: Period[]

The periods during the school day. May be empty on no-school days.

.school: boolean
.alternate: boolean
.summer: boolean

Respectively, whether or not the school day has school, has an alternate schedule, and is outside the range of the school year that it came from (which is assumed to be during summer break, hence the name).

Methods

.toJSON(): Object[]

Returns an array of plain object representations of each period; you can use JSON.stringify with this.

Period

Represents a period in a school day.

Properties

.period: string

The ID of the period. This should be compared with the constants in GunnSchedule.Periods for identification.

.start: Time
.end: Time

The start and end times of the period.

.selfGrades: number[]

Only for SELF periods: an array of grade level numbers possibly containing at least one of [9, 10, 11, 12].

Methods

.toJSON(): Object

Returns a plain object representation of the period. period has the period ID, and start and end are the totalMinutes of the start and end times, respectively.

Time

Represents a time during the day in minutes in local Gunn time.

Properties

.hour: number

The hour component of the time. An integer between 0 and 23.

.minute: number

The minute component of the time. An integer between 0 and 59.

.totalMinutes: number

The number of minutes since the beginning of the day; equivalent to time.hour * 60 + time.minute. Useful for comparing times or calculating the duration of a period.

Methods

.toTime(militaryTime: boolean = false): string

Formats the time in 12-hour (1:01 pm), or 24-hour (13:01) if militaryTime is true (it is false by default).

Development

# Run lint and tests
npm test

# Build web versions using Webpack
npm run build

# If you're on Windows, you need this to be able to run prepublishOnly (to set NODE_ENV=production):
npm install -g win-node-env

# Publish to NPM
npm publish
1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago