Skip to content

Commit

Permalink
Module 2, 3, 4
Browse files Browse the repository at this point in the history
  • Loading branch information
fekberg committed Jul 5, 2019
1 parent f77c2dd commit 6d8cf70
Show file tree
Hide file tree
Showing 73 changed files with 36,687 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Module 2/StockAnalyzer/StockAnalyzer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockAnalyzer", "StockAnalyzer\StockAnalyzer.csproj", "{BFF0EAEF-8BD9-4A7A-81A8-D79EEEA7A332}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BFF0EAEF-8BD9-4A7A-81A8-D79EEEA7A332}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFF0EAEF-8BD9-4A7A-81A8-D79EEEA7A332}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFF0EAEF-8BD9-4A7A-81A8-D79EEEA7A332}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFF0EAEF-8BD9-4A7A-81A8-D79EEEA7A332}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {106107FB-CB27-4FAE-BA6A-386AAB6F9762}
EndGlobalSection
EndGlobal
40 changes: 40 additions & 0 deletions src/Module 2/StockAnalyzer/StockAnalyzer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace StockAnalyzer
{
class Program
{
static void Main(string[] args)
{
#region Parsing a date and time given a specific format
var date = "9/10/2019 10:00:00 PM";

var parsedDate = DateTimeOffset.ParseExact(date,
"M/d/yyyy h:mm:ss tt",
CultureInfo.InvariantCulture);

Console.WriteLine(parsedDate);
#endregion

#region Formatting a date and time as ISO 8601
Console.WriteLine(parsedDate.ToString("o"));
#endregion

#region Finding time zones for a given offset
var now = DateTimeOffset.Now;

foreach (var timeZone in TimeZoneInfo.GetSystemTimeZones())
{
if (timeZone.GetUtcOffset(now) == now.Offset)
{
Console.WriteLine(timeZone);
}
}

#endregion
}
}
}
16 changes: 16 additions & 0 deletions src/Module 2/StockAnalyzer/StockAnalyzer/StockAnalyzer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyName>StockAnalyzer</AssemblyName>
<RootNamespace>StockAnalyzer</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Update="StockData.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/Module 2/StockAnalyzer/StockAnalyzer/StockData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Ticker,TradeDate,Open,High,Low,Close,Volume,Change,ChangePercent
FEK,9/10/2019 12:00:00 AM,,,,,1679887,0.0985,0.3670
FEK,9/2/2019 12:00:00 AM,,,,,8664500,0.7344,2.5970
FEK,9/2/2019 12:00:00 AM,,,,,214238,0.7280,4.7230
FEK,9/2/2019 12:00:00 AM,,,,,318351,0.3121,2.7720
FEK,9/2/2019 12:00:00 AM,,,,,637150,0.3031,0.2330
FEK,9/2/2019 12:00:00 AM,,,,,89756289,0.7202,1.1220
FEK,9/2/2019 12:00:00 AM,,,,,256342,-0.0315,-0.2400
25 changes: 25 additions & 0 deletions src/Module 3/Dates and Times in .NET/Dates and Times in .NET.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dates and Times in .NET", "Dates and Times in .NET\Dates and Times in .NET.csproj", "{1B8A9769-B62A-4D9D-B29D-DB22DCFC80B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1B8A9769-B62A-4D9D-B29D-DB22DCFC80B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B8A9769-B62A-4D9D-B29D-DB22DCFC80B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B8A9769-B62A-4D9D-B29D-DB22DCFC80B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8A9769-B62A-4D9D-B29D-DB22DCFC80B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01723DF8-D7E6-476B-A8F6-8937C7805EE5}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Dates_and_Times_in_.NET</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Globalization;

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);

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);
}

// Return the week of our adjusted day
return calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Monday);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SessionBuilder.Core
{
public class FakeSpeakerRepository : ISpeakerRepository
{
public IEnumerable<Speaker> Speakers { get; } = new List<Speaker> {
new Speaker
{
Id = Guid.Parse("5040BF0C-33E3-4AC0-BEA1-6CD4AD971BAA"),
Name = "Filip Ekberg",
Birthday = new DateTime(1987, 01, 29),

Sessions = new [] {
new Session
{
Id = Guid.Parse("593099a7-021c-47d8-bdfd-26eead842ea9"),
Title = "The state of C#",
Abstract = "In this talk I go through how C# has changed, as well as focusing on what's coming in C# 7.1, 7.2, 8.0 and beyond!",
Length = TimeSpan.FromMinutes(40),
SubmittedAt = new DateTimeOffset(2016, 02, 29, 00, 01, 00, TimeSpan.FromHours(1)), // 2016-02-29 00:01:00.0000000 +01:00
ScheduledAt = new DateTimeOffset(2019, 08, 01, 09, 40, 00, TimeSpan.FromHours(2)) // 2019-08-01 09:40:00.0000000 +02:00
},
new Session
{
Id = Guid.Parse("156ce5c3-7b0f-49b9-8cf3-5cef7075a843"),
Title = "C# 8 and Beyond",
Abstract = "One of the most popular programming language on the market is getting even better. With every iteration of C# we get more and more features that are meant to make our lives as developers a lot easier. Join me in this session to explore what's new in C# 8, as well as what we can expect in the near (and far) future of C#!",
Length = TimeSpan.FromHours(1),
SubmittedAt = new DateTimeOffset(2016, 02, 29, 00, 00, 00, TimeSpan.FromHours(1)), // 2016-02-29 00:00:00.0000000 +01:00
ScheduledAt = new DateTimeOffset(2019, 08, 01, 11, 01, 00, TimeSpan.FromHours(2)) // 2019-08-01 11:01:00.0000000 +02:00
},
new Session
{
Id = Guid.Parse("057627f8-e44e-4402-8477-cda3ff770e53"),
Title = "Succeeding with Xamarin",
Abstract = "TBA",
Length = TimeSpan.FromMinutes(55),
SubmittedAt = new DateTimeOffset(2019, 01, 01, 00, 01, 00, TimeSpan.FromHours(1)), // 2019-01-01 00:00:00.0000000 +01:00
ScheduledAt = new DateTimeOffset(2019, 08, 01, 12, 00, 00, TimeSpan.FromHours(2)) // 2019-08-01 12:00:00.0000000 +02:00
},
new Session
{
Id = Guid.Parse("8f9d4719-6d66-4406-ad26-33ea9455c11e"),
Title = "Using Dates and Times in .NET",
Abstract = "TBA",
Length = new TimeSpan(01, 45, 00),
SubmittedAt = new DateTimeOffset(2019, 01, 01, 00, 00, 00, TimeSpan.FromHours(1)), // 2019-01-01 00:00:00.0000000 +01:00
ScheduledAt = new DateTimeOffset(2019, 08, 02, 09, 00, 00, TimeSpan.FromHours(2)) // 2019-08-02 09:00:00.0000000 +02:00
}
}
}
};

public Speaker Get(string name)
{
return Speakers.FirstOrDefault(speaker => speaker.Name == name);
}

public Speaker Get(Guid id)
{
return Speakers.FirstOrDefault(speaker => speaker.Id == id);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d8cf70

Please sign in to comment.