Search Framework:
MarketWeeklyHours
Namespace: WealthLab.Core
Parent: Object

The MarketWeeklyHours class represents the trading hours for each day of a market's week. It maintains a collection of MarketHours instances keyed by day of week, with an optional default entry that applies when a specific day does not have its own hours defined. A key value of -1 represents the default market hours.

Constructors
MarketWeeklyHours
public MarketWeeklyHours(bool createCleared = false)

Creates a new MarketWeeklyHours instance. If createCleared is false, the instance is initialized with default market hours of 9:30 AM to 4:00 PM under the -1 default key. If createCleared is true, the instance is created without any market hour mappings.



Members
Clear
public void Clear()

Removes all market hour mappings from the instance.


Clone
public MarketWeeklyHours Clone()

Returns a new MarketWeeklyHours instance containing copies of all of the MarketHours mappings in this instance.


CloneOffsetHours
public MarketWeeklyHours CloneOffsetHours(double offset)

Returns a new MarketWeeklyHours instance containing the same mappings as this instance, but with offset hours added to each opening and closing time. Use MarketDetails.GetTimeZoneDifferenceInHours to calculate an appropriate offset when converting weekly hours between market time zones.


GetDayOfWeek
public static DayOfWeek GetDayOfWeek(string s)

Converts a three-letter day abbreviation such as "MON", "TUE", or "FRI" into the corresponding DayOfWeek value.


GetHours
public MarketHours GetHours(DayOfWeek dow)
public MarketHours GetHours(int n)

Returns the MarketHours associated with the specified day of week. The first overload accepts a DayOfWeek value. The second accepts its integer equivalent, where Sunday is 0 through Saturday at 6. If no specific MarketHours mapping exists for the requested day, the default mapping stored under key -1 is returned.


HoursString
public string HoursString

Returns a readable description of the market's weekly trading hours. The default hours are listed first, followed by any day-specific overrides. For example, a market might produce a string containing its standard hours followed by a special Friday schedule.


IsEmpty
public bool IsEmpty

Returns true if the instance contains no MarketHours mappings.


Mappings
public Dictionary<int, MarketHours> Mappings

Returns the Dictionary containing the market hour mappings. Keys from 0 through 6 correspond to DayOfWeek values Sunday through Saturday. The key -1 represents the default market hours used when no day-specific mapping exists.


Parse
public static MarketWeeklyHours Parse(List<string> tokens)

Creates and returns a MarketWeeklyHours instance from the persisted market-hours tokens supplied in tokens. The first two tokens define the default opening and closing times. Any remaining tokens define day-specific overrides using a three-letter day abbreviation followed by opening and closing times.


SpecifyMarketHours
public void SpecifyMarketHours(int dayOfWeek, TimeSpan mktOpen, TimeSpan mktClose)

Assigns market hours for the specified dayOfWeek. Pass a value from 0 through 6 corresponding to Sunday through Saturday to define hours for a specific day. Pass -1 to define the default market hours used for days that do not have their own specific mapping.


ToString
public override string ToString()

Returns a persisted string representation of the day-specific market hours. Only mappings for specific days are included. The default -1 mapping is not included because it is persisted separately by MarketDetails.