Pixi’VN
indexInterfaces

Interface: TimeHandlerInterface

nqtr on GitHub

Defined in: src/interface/TimeHandlerInterface.ts:7

Handler that manages the time of the game: the current time and date, the day/week structure and the time slots.

Properties

currentDayName

> readonly currentDayName: string

Defined in: src/interface/TimeHandlerInterface.ts:78

The current week day name. If the week days names are not defined, then it will return an empty string. For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.

Default

""

currentTimeSlot

> readonly currentTimeSlot: number

Defined in: src/interface/TimeHandlerInterface.ts:93

The index of the current time slot in timeSlots. You can use this property to create "Image that changes based on the time period":

Example

import { timeTracker } from '@drincs/nqtr';

function changeBackground() {
    return (
        <img src={`background-${timeTracker.currentTimeSlot}.png`} />
    )
}

currentWeekDayNumber

> readonly currentWeekDayNumber: number

Defined in: src/interface/TimeHandlerInterface.ts:72

The current week day number (from: 1 - to: weekLength). For example, if the week length is 7 and the current day is 10, then the result will be 4.


dayEndTime

> readonly dayEndTime: number

Defined in: src/interface/TimeHandlerInterface.ts:20

The time at which a day ends. When the time reaches it, the date increases.


dayStartTime

> readonly dayStartTime: number

Defined in: src/interface/TimeHandlerInterface.ts:16

The time at which a day starts.


defaultTimeSpent

> readonly defaultTimeSpent: number

Defined in: src/interface/TimeHandlerInterface.ts:24

The default time spent by increaseTime when no delta is given.


getDayName

> readonly getDayName: ((weekDayNumber) => string) | undefined

Defined in: src/interface/TimeHandlerInterface.ts:49

Week days name

Param

weekDayNumber

The current week day number (from: 0 - to: weekLength - 1).

Returns

The name of the week day.

Example

(weekDayNumber: number) => {
    const weekDaysNames = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
    return weekDaysNames[weekDayNumber];
}

isWeekend

> readonly isWeekend: boolean

Defined in: src/interface/TimeHandlerInterface.ts:67

If the current day is greater than or equal to the weekend start day, then it will return true.


timeSlots

> readonly timeSlots: ITimeStlot[]

Defined in: src/interface/TimeHandlerInterface.ts:28

The time slots of a day (e.g. morning, afternoon, evening).


weekendStartDay

> readonly weekendStartDay: number

Defined in: src/interface/TimeHandlerInterface.ts:36

The week day (starting from 0) from which the weekend starts.


weekLength

> readonly weekLength: number

Defined in: src/interface/TimeHandlerInterface.ts:32

The number of days in a week.

Accessors

currentDate

Get Signature

> get currentDate(): number

Defined in: src/interface/TimeHandlerInterface.ts:62

The current date. Date is a numeric variable used to determine and manage the number of days passed. It's recommended to use currentDate as if it were the current day. Setting it to undefined resets it to 0.

Returns

number

Set Signature

> set currentDate(value): void

Defined in: src/interface/TimeHandlerInterface.ts:63

Parameters
value

number | undefined

Returns

void


currentTime

Get Signature

> get currentTime(): number

Defined in: src/interface/TimeHandlerInterface.ts:55

The current time. Time is a numeric variable used to determine and manage time during a day/date. It's recommended to use currentTime as if it were the current time. If you also want to manage minutes, you can use a float value. Setting it to undefined resets it to dayStartTime.

Returns

number

Set Signature

> set currentTime(value): void

Defined in: src/interface/TimeHandlerInterface.ts:56

Parameters
value

number | undefined

Returns

void

Methods

increaseDate()

> increaseDate(delta?, time?): number

Defined in: src/interface/TimeHandlerInterface.ts:107

Increase the current date by the given delta.

Parameters

delta?

number

The number of days to increase (default: 1).

time?

number

The time of the new day (default: dayStartTime).

Returns

number

The new current date.


increaseTime()

> increaseTime(delta?): number

Defined in: src/interface/TimeHandlerInterface.ts:100

Increase the current time by the given time spent. If the new time is greater than or equal to dayEndTime, then it will increase the day and set the new time.

Parameters

delta?

number

The time spent (default: defaultTimeSpent).

Returns

number

The new current time.


initialize()

> initialize(settings): void

Defined in: src/interface/TimeHandlerInterface.ts:12

Set the time settings. Omitted values fall back to their defaults.

Parameters

settings

TimeSettings

The time settings.

Returns

void


nowIsBetween()

> nowIsBetween(fromTime, toTime): boolean

Defined in: src/interface/TimeHandlerInterface.ts:114

Check if the current time is between the given times.

Parameters

fromTime

number | undefined

The starting time. If the currentTime is equal to this time, the function will return true. If undefined, the day start is used.

toTime

number | undefined

The ending time. If undefined, the day end is used.

Returns

boolean

true if the current time is between the given times, otherwise false.

On this page