-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
1,416 additions
and
36,273 deletions.
There are no files selected for viewing
80 changes: 6 additions & 74 deletions
80
src/Module 3/Dates and Times in .NET/Dates and Times in .NET/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,21 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Dates_and_Times_in_.NET | ||
namespace Dates_and_Times_in.NET | ||
{ | ||
class Program | ||
{ | ||
private static Calendar calendar = CultureInfo.InvariantCulture.Calendar; | ||
|
||
static void Main(string[] args) | ||
{ | ||
#region Calculating time difference and working with TimeSpan | ||
var start = DateTimeOffset.UtcNow; | ||
var end = start.AddSeconds(45); | ||
|
||
TimeSpan difference = end - start; | ||
|
||
difference = difference.Multiply(2); | ||
|
||
Console.WriteLine(difference.TotalMinutes); | ||
#endregion | ||
|
||
#region Getting the week number | ||
start = new DateTimeOffset(2007, 12, 31, 0, 0, 0, TimeSpan.Zero); | ||
|
||
var week = calendar.GetWeekOfYear(start.DateTime, | ||
CalendarWeekRule.FirstFourDayWeek, | ||
DayOfWeek.Monday); | ||
|
||
Console.WriteLine(week); | ||
|
||
// Only for .NET Core 3.0 | ||
// var isoWeek = ISOWeek.GetWeekOfYear(start.DateTime); | ||
|
||
// Console.WriteLine(isoWeek); | ||
|
||
var isoWeekHack = GetIso8601WeekOfYear(start.DateTime); | ||
|
||
Console.WriteLine(isoWeekHack); | ||
#endregion | ||
|
||
#region Extending a date | ||
var contractDate = new DateTimeOffset(2019, 7, 1, 0, 0, 0, TimeSpan.Zero); | ||
|
||
contractDate = contractDate.AddMonths(6).AddTicks(-1); | ||
TimeSpan difference = start - end; | ||
|
||
Console.WriteLine(difference.TotalSeconds); | ||
|
||
Console.WriteLine(contractDate); | ||
|
||
contractDate = new DateTimeOffset(2020, 2, 29, 0, 0, 0, TimeSpan.Zero); | ||
|
||
Console.WriteLine(contractDate); | ||
|
||
contractDate = contractDate.AddMonths(1); | ||
|
||
Console.WriteLine(contractDate); | ||
#endregion | ||
} | ||
|
||
public static DateTimeOffset ExtendContract(DateTimeOffset current, int months) | ||
{ | ||
var future = current.AddMonths(months).AddTicks(-1); | ||
|
||
return new DateTimeOffset(future.Year, | ||
future.Month, | ||
DateTime.DaysInMonth(future.Year, future.Month), | ||
23, 59, 59, | ||
current.Offset); | ||
} | ||
|
||
// Code snippet from: https://blogs.msdn.microsoft.com/shawnste/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net/ | ||
// This presumes that weeks start with Monday. | ||
// Week 1 is the 1st week of the year with a Thursday in it. | ||
public static int GetIso8601WeekOfYear(DateTime time) | ||
{ | ||
// Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll | ||
// be the same week# as whatever Thursday, Friday or Saturday are, | ||
// and we always get those right | ||
DayOfWeek day = calendar.GetDayOfWeek(time); | ||
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday) | ||
{ | ||
time = time.AddDays(3); | ||
} | ||
var timeSpan = new TimeSpan(1, 61, 0) | ||
|
||
// Return the week of our adjusted day | ||
return calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, | ||
DayOfWeek.Monday); | ||
Console.WriteLine(timeSpan.Hours); | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
src/Module 4/SessionBuilder/SessionBuilder.Core/SessionBuilderContext.cs
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
src/Module 4/SessionBuilder/SessionBuilder.Core/SpeakerRepository.cs
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/Module 4/SessionBuilder/SessionBuilder.Web/Pages/DownloadController.cs
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/Module 4/SessionBuilder/SessionBuilder.Web/Pages/Error.cshtml
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/Module 4/SessionBuilder/SessionBuilder.Web/Pages/Error.cshtml.cs
This file was deleted.
Oops, something went wrong.
80 changes: 0 additions & 80 deletions
80
src/Module 4/SessionBuilder/SessionBuilder.Web/Pages/Index.cshtml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.