Skip to content

Commit 9f56213

Browse files
committed
Merge branch 'release/v0.3'
2 parents 46e146d + f92bd45 commit 9f56213

File tree

6 files changed

+87
-4
lines changed

6 files changed

+87
-4
lines changed

seminar.gpr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ project Seminar is
44

55
for Object_Dir use "obj";
66
for Exec_Dir use ".";
7-
for Main use ("seminar-main.adb");
87
type Build_Kind is
98
("static", "relocatable", "static-pic");
109
Xmlada_Build : Build_Kind := external ("XMLADA_BUILD");
@@ -26,17 +25,21 @@ project Seminar is
2625
case Florist_Build is
2726

2827
when "default" =>
28+
for Main use ("debug.adb", "seminar-main.adb");
2929
for Source_Dirs use ("src/**", "../tools/XMLAda/xmlada-3.2.1-src/**", "../tools/adacgi-1.6");
3030
end case;
3131

3232
when "relocatable" =>
33+
for Main use ("seminar-main.adb");
3334
for Source_Dirs use ("src");
3435
end case;
3536

3637
when "relocatable" =>
38+
for Main use ("seminar-main.adb");
3739
for Source_Dirs use ("src");
3840

3941
when "static-pic" =>
42+
for Main use ("seminar-main.adb");
4043
for Source_Dirs use ("src");
4144
end case;
4245

src/debug.adb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
with Ada.Text_IO;
2+
with GNAT.Calendar;
3+
with Ada.Calendar;
4+
with GNAT.Calendar.Time_IO;
5+
with Ada.Calendar.Time_Zones;
6+
use Ada.Calendar;
7+
8+
9+
procedure Debug is
10+
Year, Month, Day, Hour, Minute, Second : Natural;
11+
Sub_Second, Seconds : Duration;
12+
begin
13+
Ada.Text_IO.Put_Line (GNAT.Calendar.Time_IO.Image (Ada.Calendar.Clock, "%c"));
14+
GNAT.Calendar.Split (Ada.Calendar.Clock,
15+
Year,
16+
Month,
17+
Day,
18+
Hour,
19+
Minute,
20+
Second,
21+
Sub_Second);
22+
Ada.Text_IO.Put_Line ("Split: " & Hour'Img & ":" & Minute'Img);
23+
GNAT.Calendar.Split_At_Locale (Ada.Calendar.Clock,
24+
Year,
25+
Month,
26+
Day,
27+
Hour,
28+
Minute,
29+
Second,
30+
Sub_Second);
31+
Ada.Text_IO.Put_Line ("Split_At_Locale: " & Hour'Img & ":" & Minute'Img);
32+
Ada.Calendar.Split (Ada.Calendar.Clock, Year, Month, Day, Seconds);
33+
Second := Integer (Seconds);
34+
Hour := Second / 3_600;
35+
Minute := (Second - Hour * 3_600) / 60;
36+
Ada.Text_IO.Put_Line ("Ada.Calendar.Split: " & Integer'Image (Hour) & ":" & Integer'Image (Minute));
37+
Ada.Text_IO.Put_Line ("TZ Offset (Clock): " & Integer'Image (Integer (Ada.Calendar.Time_Zones.UTC_Time_Offset (Ada.Calendar.Clock))));
38+
Ada.Text_IO.Put_Line ("TZ Offset (Clock-30d): " & Integer'Image (Integer (Ada.Calendar.Time_Zones.UTC_Time_Offset (Ada.Calendar.Clock - Duration (3_600*24*30)))));
39+
end Debug;

src/events.adb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ package body Events is
3030
function To_String (Prefix : String;
3131
T : Ada.Calendar.Time;
3232
All_Day : Boolean) return String;
33+
function To_String (Prefix : String;
34+
T : Local_Time;
35+
All_Day : Boolean) return String;
3336

3437
function Get_Value (Fields : Named_Node_Map;
3538
Name : String) return String;
@@ -267,6 +270,20 @@ package body Events is
267270
end if;
268271
end To_String;
269272

273+
function To_String (Prefix : String;
274+
T : Local_Time;
275+
All_Day : Boolean) return String is
276+
The_Time : constant Ada.Calendar.Time := Ada.Calendar.Time (T);
277+
begin
278+
if All_Day then
279+
return Prefix & ";TZID=" & Utils.Get_Timezone & ";VALUE=DATE:"
280+
& GNAT.Calendar.Time_IO.Image (The_Time, "%Y%m%d");
281+
else
282+
return Prefix & ";TZID=" & Utils.Get_Timezone & ":"
283+
& GNAT.Calendar.Time_IO.Image (The_Time, "%Y%m%dT%H%M%S");
284+
end if;
285+
end To_String;
286+
270287
function To_String (I : Interval) return String is
271288
begin
272289
return Interval'Image (I);
@@ -350,8 +367,10 @@ package body Events is
350367
Write ("UID:" & Item.UID);
351368
Write ("STATUS:CONFIRMED");
352369
Write (To_String ("LAST-MODIFIED", Item.Last_Modified, False));
353-
Write (To_String ("DTSTART", Item.Event_Date, Item.Is_All_Day));
354-
Write (To_String ("DTEND", Item.Event_Date + Item.Event_Duration,
370+
Write (To_String ("DTSTART", UTC_To_Local (Item.Event_Date),
371+
Item.Is_All_Day));
372+
Write (To_String ("DTEND",
373+
UTC_To_Local (Item.Event_Date + Item.Event_Duration),
355374
Item.Is_All_Day));
356375
Write_Recurrence (Item);
357376
Write_Exceptions (Item);

src/seminar-main.adb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ with CGI;
1313

1414
with Convert;
1515
with Pipe_Streams; use Pipe_Streams;
16+
with Utils;
1617

1718
procedure Seminar.Main is
1819
use Ada.Command_Line;
@@ -22,7 +23,7 @@ procedure Seminar.Main is
2223
procedure Append (Source : in out POSIX.POSIX_String_List;
2324
New_Item : Unbounded_String);
2425

25-
Version : constant String := "v0.2";
26+
Version : constant String := "v0.3";
2627
Config_File : Ada.Text_IO.File_Type;
2728
Wget_Command : Pipe_Stream;
2829
Reader : DOM.Readers.Tree_Reader;
@@ -85,6 +86,8 @@ begin
8586
URL := To_Unbounded_String (Value);
8687
elsif Name = "request" then
8788
Request := To_Unbounded_String (Value);
89+
elsif Name = "timezone" then
90+
Utils.Timezone := To_Unbounded_String (Value);
8891
else
8992
raise Config_Error with
9093
"Unknown name """ & Name & """";

src/utils.adb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ with Ada.Characters;
33
with Ada.Characters.Latin_1;
44
with GNAT.Calendar;
55
with GNAT.Calendar.Time_IO;
6+
with Ada.Calendar.Time_Zones;
67

78
package body Utils is
89

@@ -27,6 +28,11 @@ package body Utils is
2728
return Result (1 .. K);
2829
end Clean_Text;
2930

31+
function Get_Timezone return String is
32+
begin
33+
return Ada.Strings.Unbounded.To_String (Timezone);
34+
end Get_Timezone;
35+
3036
function Shift (S : String) return String is
3137
Result : constant String (1 .. S'Length) := S;
3238
begin
@@ -84,6 +90,13 @@ package body Utils is
8490
return Result (1 .. R - 1);
8591
end Unescape;
8692

93+
function UTC_To_Local (T : Ada.Calendar.Time) return Local_Time is
94+
use Ada.Calendar;
95+
begin
96+
return Local_Time (T
97+
+ 60 * Duration (Time_Zones.UTC_Time_Offset (T)));
98+
end UTC_To_Local;
99+
87100
procedure Warn (Text : String) is
88101
use Ada.Text_IO;
89102
begin

src/utils.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
with Ada.Calendar;
2+
with Ada.Strings.Unbounded;
23

34
package Utils is
5+
type Local_Time is new Ada.Calendar.Time;
6+
Timezone : Ada.Strings.Unbounded.Unbounded_String;
7+
48
function Shift (S : String) return String;
59
function Unescape (S : String) return String;
610
procedure Warn (Text : String);
711
function Clean_Text (Source : String) return String;
812
function To_Time (Source : String) return Ada.Calendar.Time;
913
function To_String (N : Natural) return String;
14+
function UTC_To_Local (T : Ada.Calendar.Time) return Local_Time;
15+
function Get_Timezone return String;
1016
end Utils;

0 commit comments

Comments
 (0)