Skip to content

Commit a899fcc

Browse files
committed
Factored subroutine for time-related properties generation
1 parent 1fe73d8 commit a899fcc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

arduino/cores/packagemanager/package_manager.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import (
1919
"fmt"
2020
"net/url"
2121
"path"
22+
"strconv"
2223
"strings"
2324
"sync"
25+
"time"
2426

2527
"github.com/arduino/arduino-cli/arduino/cores"
2628
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
@@ -29,6 +31,7 @@ import (
2931
"github.com/arduino/arduino-cli/i18n"
3032
paths "github.com/arduino/go-paths-helper"
3133
properties "github.com/arduino/go-properties-orderedmap"
34+
"github.com/arduino/go-timeutils"
3235
"github.com/sirupsen/logrus"
3336
semver "go.bug.st/relaxed-semver"
3437
)
@@ -331,6 +334,11 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
331334
for _, tool := range requiredTools {
332335
buildProperties.Merge(tool.RuntimeProperties())
333336
}
337+
now := time.Now()
338+
buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10))
339+
buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10))
340+
buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now)))
341+
buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now)))
334342

335343
// No errors... phew!
336344
return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil

legacy/builder/setup_build_properties.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ package builder
1818
import (
1919
"os"
2020
"path/filepath"
21-
"strconv"
2221
"strings"
23-
"time"
2422

2523
"github.com/arduino/arduino-cli/arduino/cores"
2624
"github.com/arduino/arduino-cli/legacy/builder/types"
2725
properties "github.com/arduino/go-properties-orderedmap"
28-
timeutils "github.com/arduino/go-timeutils"
2926
"github.com/pkg/errors"
3027
)
3128

@@ -96,12 +93,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
9693

9794
buildProperties.SetPath("build.source.path", ctx.Sketch.FullPath)
9895

99-
now := time.Now()
100-
buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10))
101-
buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10))
102-
buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now)))
103-
buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now)))
104-
10596
buildProperties.Merge(ctx.PackageManager.GetCustomGlobalProperties())
10697

10798
keychainProp := buildProperties.ContainsKey("build.keys.keychain")

0 commit comments

Comments
 (0)