Class DayPart
- Namespace
- Cuemon
- Assembly
- Cuemon.Core.dll
Represents a part of a day. The built-in parts of day supports a roughly way to determine whether it is; Night, Morning, Forenoon, Afternoon or Evening. Keep in mind that there is no exact science for day parts; it is as much a cultural as it is a personal preference.
public class DayPart
- Inheritance
-
DayPart
Examples
The following example demonstrates how to use DayPart to determine the current part of the day and enumerate all built-in day parts.
using System;
using System.Linq;
using Cuemon;
namespace MyApp.Examples;
public class DayPartExample
{
public void Demonstrate()
{
var now = DateTime.Now.TimeOfDay;
var current = DayPart.All.FirstOrDefault(dp =>
now >= dp.Range.Start && now < dp.Range.End);
Console.WriteLine($"Current time: {now:hh\\:mm}");
Console.WriteLine($"Day part: {current?.Name ?? "Unknown"}");
Console.WriteLine("All day parts:");
foreach (var part in DayPart.All)
{
Console.WriteLine($" {part}");
}}
}
Constructors
DayPart(string, TimeRange)
Initializes a new instance of the DayPart class.
public DayPart(string name, TimeRange range)
Parameters
Properties
Afternoon
Gets the day part of a 24-hour period that approximates to Afternoon.
public static DayPart Afternoon { get; }
Property Value
- DayPart
The range of a 24-hour period that approximates to Afternoon.
All
Gets the day parts of a 24-hour range of period.
public static IEnumerable<DayPart> All { get; }
Property Value
- IEnumerable<DayPart>
The day parts of a 24-hour range of period.
Evening
Gets the day part of a 24-hour period that approximates to Evening.
public static DayPart Evening { get; }
Property Value
- DayPart
The range of a 24-hour period that approximates to Evening.
Forenoon
Gets the day part of a 24-hour period that approximates to Forenoon.
public static DayPart Forenoon { get; }
Property Value
- DayPart
The range of a 24-hour period that approximates to Forenoon.
Morning
Gets the day part of a 24-hour period that approximates to Morning.
public static DayPart Morning { get; }
Property Value
- DayPart
The range of a 24-hour period that approximates to Morning.
Name
Gets the name of a DayPart.
public string Name { get; }
Property Value
Night
Gets the day part of a 24-hour period that approximates to Night.
public static DayPart Night { get; }
Property Value
- DayPart
The range of a 24-hour period that approximates to Night.
Range
Gets the approximate range that this DayPart represents.
public TimeRange Range { get; set; }
Property Value
Methods
ToString()
Returns a string that represents this instance.
public override string ToString()