-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for start/end othert than sunrise or sunset
- Loading branch information
1 parent
c07e871
commit 67050f7
Showing
13 changed files
with
418 additions
and
34 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FF.Temperature.Lib | ||
{ | ||
public interface ITimeRangeProvider | ||
{ | ||
WeatherInformation GetInformation(IUserInteraction userInteraction, DateTime date, double latitude, double longitude); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FF.Temperature.Lib | ||
{ | ||
public static class TimeRangeProviderFactory | ||
{ | ||
private class FixedTimeProvider : ITimeRangeProvider | ||
{ | ||
private int startTime; | ||
private int endTime; | ||
|
||
public FixedTimeProvider(int startTime, int endTime) | ||
{ | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
public WeatherInformation GetInformation(IUserInteraction userInteraction, DateTime date, double latitude, double longitude) | ||
{ | ||
return new WeatherInformation( | ||
date.Date.AddHours(startTime), | ||
date.Date.AddHours(endTime + 12), | ||
Enumerable.Empty<WeatherReading>()); | ||
} | ||
} | ||
|
||
private class CompositeProvider : ITimeRangeProvider | ||
{ | ||
private ITimeRangeProvider startTime; | ||
private ITimeRangeProvider endTime; | ||
|
||
public CompositeProvider(ITimeRangeProvider startTime, ITimeRangeProvider endTime) | ||
{ | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
public WeatherInformation GetInformation(IUserInteraction userInteraction, DateTime date, double latitude, double longitude) | ||
{ | ||
WeatherInformation start = this.startTime.GetInformation(userInteraction, date, latitude, longitude); | ||
WeatherInformation end = this.endTime.GetInformation(userInteraction, date, latitude, longitude); | ||
return new WeatherInformation( | ||
start.StartTime, | ||
end.EndTime, | ||
Enumerable.Empty<WeatherReading>()); | ||
} | ||
} | ||
|
||
public static ITimeRangeProvider GetProvider(int startTime, int endTime) | ||
{ | ||
if (startTime == 0 && endTime == 0) | ||
{ | ||
return new SunriseSunset(); | ||
} | ||
else | ||
{ | ||
var fixedTimeProvider = new FixedTimeProvider(startTime, endTime); | ||
|
||
if (startTime == 0) | ||
{ | ||
return new CompositeProvider( | ||
new SunriseSunset(), | ||
fixedTimeProvider); | ||
} | ||
else if (endTime == 0) | ||
{ | ||
return new CompositeProvider( | ||
fixedTimeProvider, | ||
new SunriseSunset()); | ||
} | ||
else | ||
{ | ||
return fixedTimeProvider; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.