Skip to content

Commit 7ab1e5e

Browse files
author
Elvis Souza
committed
Adjustments in ToTime Function
1 parent 3dd4698 commit 7ab1e5e

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
5+
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
6+
}
7+
}

AzureDevopsStateTracker/Migrations/20210720105645_FunctionToTimeInitial.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,37 @@ public partial class FunctionToTimeInitial : Migration
77
{
88
protected override void Up(MigrationBuilder migrationBuilder)
99
{
10-
var rawFunction = @"CREATE OR ALTER FUNCTION ToTime (@segundos float)
11-
RETURNS TIME
12-
AS BEGIN
13-
return CONVERT(TIME, DATEADD(SECOND, @segundos + 86400000, 0), 114)
14-
END";
10+
var rawFunction = @"CREATE OR ALTER FUNCTION ToTime (@seconds int)
11+
RETURNS varchar(50)
12+
AS BEGIN
13+
declare @seconds_in_a_day int = 86400;
14+
declare @seconds_in_an_hour int = 3600;
15+
declare @seconds_in_a_minute int = 60;
16+
17+
declare @text_to_return varchar(50) = '';
18+
if(@seconds >= @seconds_in_a_day)
19+
begin
20+
declare @completed_days int = @seconds/@seconds_in_a_day;
21+
select @text_to_return = CONCAT(@text_to_return, @completed_days, ' day(s)')
22+
select @seconds = @seconds - (@seconds_in_a_day * @completed_days)
23+
end
24+
25+
if(@seconds >= @seconds_in_an_hour)
26+
begin
27+
declare @completed_hours int = @seconds/@seconds_in_an_hour;
28+
select @text_to_return = CONCAT(@text_to_return, ' ', @completed_hours, ' hour(s)')
29+
select @seconds = @seconds - (@seconds_in_an_hour * @completed_hours)
30+
end
31+
32+
if(@seconds >= @seconds_in_a_minute)
33+
begin
34+
declare @completed_minutes int = @seconds/@seconds_in_a_minute;
35+
select @text_to_return = CONCAT(@text_to_return, ' ', @completed_minutes, ' minute(s)')
36+
select @seconds = @seconds - (@seconds_in_a_minute * @completed_minutes)
37+
end
38+
39+
return LTRIM(RTRIM(@text_to_return));
40+
END";
1541
migrationBuilder.Sql(rawFunction);
1642
}
1743

0 commit comments

Comments
 (0)