Skip to content

Commit d15f1df

Browse files
author
Federico Fissore
committed
Added extra.time.* entries to build properties
Signed-off-by: Federico Fissore <[email protected]>
1 parent f470b4c commit d15f1df

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

Diff for: src/arduino.cc/builder/constants/constants.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const BUILD_PROPERTIES_BUILD_VARIANT_PATH = "build.variant.path"
4848
const BUILD_PROPERTIES_COMPILER_CPP_FLAGS = "compiler.cpp.flags"
4949
const BUILD_PROPERTIES_COMPILER_PATH = "compiler.path"
5050
const BUILD_PROPERTIES_COMPILER_WARNING_FLAGS = "compiler.warning_flags"
51+
const BUILD_PROPERTIES_EXTRA_TIME_DST = "extra.time.dst"
52+
const BUILD_PROPERTIES_EXTRA_TIME_LOCAL = "extra.time.local"
53+
const BUILD_PROPERTIES_EXTRA_TIME_UTC = "extra.time.utc"
54+
const BUILD_PROPERTIES_EXTRA_TIME_ZONE = "extra.time.zone"
5155
const BUILD_PROPERTIES_INCLUDES = "includes"
5256
const BUILD_PROPERTIES_OBJECT_FILE = "object_file"
5357
const BUILD_PROPERTIES_OBJECT_FILES = "object_files"

Diff for: src/arduino.cc/builder/setup_build_properties.go

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"arduino.cc/builder/utils"
3636
"path/filepath"
3737
"strings"
38+
"time"
3839
)
3940

4041
type SetupBuildProperties struct{}
@@ -105,6 +106,12 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}) error {
105106
buildProperties[constants.BUILD_PROPERTIES_SOURCE_PATH] = sourcePath
106107
}
107108

109+
now := time.Now()
110+
buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_UTC] = string(now.Unix())
111+
buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_LOCAL] = string(utils.LocalUnix(now))
112+
buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_ZONE] = string(utils.TimezoneOffset())
113+
buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_DST] = string(utils.DaylightSavingsOffset(now))
114+
108115
context[constants.CTX_BUILD_PROPERTIES] = buildProperties
109116

110117
return nil

Diff for: src/arduino.cc/builder/test/setup_build_properties_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/props"
3636
"arduino.cc/builder/types"
37+
"arduino.cc/builder/utils"
3738
"github.com/stretchr/testify/require"
3839
"os"
3940
"path/filepath"
@@ -99,6 +100,11 @@ func TestSetupBuildProperties(t *testing.T) {
99100
require.Equal(t, Abs(t, "./downloaded_tools/avr-gcc/4.8.1-arduino5"), buildProperties["runtime.tools.avr-gcc-4.8.1-arduino5.path"])
100101

101102
require.Equal(t, Abs(t, filepath.Join("sketch1", "sketch.ino")), buildProperties[constants.BUILD_PROPERTIES_SOURCE_PATH])
103+
104+
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_UTC))
105+
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_LOCAL))
106+
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_ZONE))
107+
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_DST))
102108
}
103109

104110
func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) {

Diff for: src/arduino.cc/builder/test/time_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package test
31+
32+
import (
33+
"arduino.cc/builder/utils"
34+
"github.com/stretchr/testify/require"
35+
"testing"
36+
"time"
37+
)
38+
39+
func TestTime(t *testing.T) {
40+
loc, err := time.LoadLocation("CET")
41+
NoError(t, err)
42+
43+
firstJanuary2015 := time.Date(2015, 1, 1, 0, 0, 0, 0, loc)
44+
require.Equal(t, int64(1420066800), firstJanuary2015.Unix())
45+
require.Equal(t, int64(1420066800+3600), utils.LocalUnix(firstJanuary2015))
46+
require.Equal(t, 3600, utils.TimezoneOffset())
47+
require.Equal(t, 0, utils.DaylightSavingsOffset(firstJanuary2015))
48+
49+
thisFall := time.Date(2015, 9, 23, 0, 0, 0, 0, loc)
50+
require.Equal(t, int64(1442959200), thisFall.Unix())
51+
require.Equal(t, int64(1442959200+3600+3600), utils.LocalUnix(thisFall))
52+
require.Equal(t, 3600, utils.TimezoneOffset())
53+
require.Equal(t, 3600, utils.DaylightSavingsOffset(thisFall))
54+
}

Diff for: src/arduino.cc/builder/utils/time.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package utils
31+
32+
import "time"
33+
34+
func TimezoneOffset() int {
35+
_, offset := time.Unix(0, 0).Zone()
36+
return offset
37+
}
38+
39+
func DaylightSavingsOffset(t time.Time) int {
40+
_, offset := t.Zone()
41+
return offset - TimezoneOffset()
42+
}
43+
44+
func LocalUnix(t time.Time) int64 {
45+
return t.Unix() + int64(TimezoneOffset()) + int64(DaylightSavingsOffset(t))
46+
}

0 commit comments

Comments
 (0)