DayPart Class
Definition
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
-
objectDayPart
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
| Name | Description |
|---|---|
| DayPart(string, TimeRange) | Initializes a new instance of the DayPart class. |
Properties
| Name | Description |
|---|---|
| Afternoon | Gets the day part of a 24-hour period that approximates to Afternoon. |
| All | Gets the day parts of a 24-hour range of period. |
| Evening | Gets the day part of a 24-hour period that approximates to Evening. |
| Forenoon | Gets the day part of a 24-hour period that approximates to Forenoon. |
| Morning | Gets the day part of a 24-hour period that approximates to Morning. |
| Name | Gets the name of a DayPart. |
| Night | Gets the day part of a 24-hour period that approximates to Night. |
| Range | Gets the approximate range that this DayPart represents. |
Methods
| Name | Description |
|---|---|
| ToString() | Returns a string that represents this instance. |