Hergine Richemont

Learning just for the fun of it

Time and Timezone in C#

C# Track, Exercism #44 Beauty Salon Goes Global

Relevant link


Github solution: exercism-solutions/beauty-salon-goes-global

Exercism #43: Beauty Salon Goes Global

Learning Goal

Time | Timezone

Relevant Information

In .NET, the concept of time is primarily represented by the DateTime struct. It provides functionality for working with dates and times, including converting between local time and UTC. Time-based calculations and arithmetic can be performed using the TimeSpan struct.

The TimeZoneInfo class provides functionality for working with different time zones and handling the differences between them. It also includes methods for working with Daylight Saving Time (DST).

For culture-specific date and time formatting, the CultureInfo class provides locale-dependent formats based on the user’s culture.

When developing cross-platform applications, the RuntimeInformation class can be used to determine the operating system on which the application is running, such as Windows, Linux, or macOS.

Task 1: 1. Provide local time equivalents of UTC (Universal Coordinated Time) appointments for the administrators

I used DateTime method ToLocalTime() to make the conversion.

Task 2: Schedule appointments in New York, London and Paris

I used RunTimeInformation method IsOSPlatform() to detect the Operating System then conevert to UTC tie accordingly using the TimeZoneInfo method ConvertTimeToUtc()

Task 3: Provide alerts to clients at intervals before the appointment

I used DateTime methods: AddDays(), AddHours(), AddMinutes() to return the exact Alert time.

Task 4: If daylight savings has recently changed, we send a message to clients reminding them.

First, I determined the timezone I was dealing with based on the location taking into account the operating system.

Then I converted UTC time to local time

I then checked if the day light saving has become active or inactive over the last 7 days.

Task 5: Use the local date time format to enter appointments

First, I determined and stored the culture info based on the location. Then, I returned a DateTime object if matched and the default value {1, 1, 1, 0, 0, 0}.


Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted