-
Notifications
You must be signed in to change notification settings - Fork 3
/
UWeatherServiceTypes.pas
80 lines (62 loc) · 1.8 KB
/
UWeatherServiceTypes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
unit UWeatherServiceTypes;
interface
uses
System.SysUtils
, System.Generics.Collections
;
type
TWeatherLocation = class
private
FName: String;
FLatitude: Double;
FLongitude: Double;
FCountry: String;
public
property Name: String read FName write FName;
property Country: String read FCountry write FCountry;
property Latitude: Double read FLatitude write FLatitude;
property Longitude: Double read FLongitude write FLongitude;
end;
TWeatherForecast = class
private
FDt: TDateTime;
FTemperature: Double;
FHumidity: Integer;
FDescription: String;
FIcon: String;
FPropPrec: Integer;
function GetDtReadable: String;
function GetIconUrl: String;
public
property Dt: TDateTime read FDt write FDt;
property Temperature: Double read FTemperature write FTemperature;
property Humidity: Integer read FHumidity write FHumidity;
property Description: String read FDescription write FDescription;
property Icon: String read FIcon write FIcon;
property PropPrec: Integer read FPropPrec write FPropPrec;
property IconUrl: String read GetIconUrl;
property DtReadable: String read GetDtReadable;
end;
TWeatherForecastsArray = array of TWeatherForecast;
TWeatherForecasts = TObjectList<TWeatherForecast>;
implementation
uses
DateUtils
;
const
URL_ICON = 'https://openweathermap.org/img/wn/%[email protected]';
{ TWeatherForecast }
function TWeatherForecast.GetDtReadable: String;
var
LFormat: TFormatSettings;
begin
LFormat := TFormatSettings.Create;
LFormat.ShortDateFormat := 'ddd mmm d, yyyy';
LFormat.LongTimeFormat := '''@'' ham/pm';
Result := DateTimeToStr( UniversalTimeToLocal(Dt), LFormat );
end;
function TWeatherForecast.GetIconUrl: String;
begin
Result := Format( URL_ICON, [Icon] );
end;
end.