mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Use UTC-based timestamp
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from platformio import __accounts_api__, app
|
||||
from platformio import __accounts_api__, app, util
|
||||
from platformio.exception import PlatformioException
|
||||
from platformio.http import HTTPClient, HTTPClientError
|
||||
|
||||
@ -68,7 +68,7 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
|
||||
return os.environ.get("PLATFORMIO_AUTH_TOKEN")
|
||||
auth = app.get_state_item("account", {}).get("auth", {})
|
||||
if auth.get("access_token") and auth.get("access_token_expire"):
|
||||
if auth.get("access_token_expire") > time.time():
|
||||
if auth.get("access_token_expire") > util.get_timestamp():
|
||||
return auth.get("access_token")
|
||||
if auth.get("refresh_token"):
|
||||
try:
|
||||
|
@ -18,10 +18,9 @@ import json
|
||||
import os
|
||||
import platform
|
||||
import socket
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from platformio import __version__, exception, fs, proc
|
||||
from platformio import __version__, exception, fs, proc, util
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data
|
||||
from platformio.package.lockfile import LockFile
|
||||
from platformio.project.config import ProjectConfig
|
||||
@ -254,7 +253,7 @@ def get_cid():
|
||||
cid = str(cid)
|
||||
if IS_WINDOWS or os.getuid() > 0: # pylint: disable=no-member
|
||||
set_state_item("cid", cid)
|
||||
set_state_item("created_at", int(time.time()))
|
||||
set_state_item("created_at", int(util.get_timestamp()))
|
||||
return cid
|
||||
|
||||
|
||||
|
@ -72,7 +72,8 @@ DEFAULT_ENV_OPTIONS = dict(
|
||||
variables=clivars,
|
||||
# Propagating External Environment
|
||||
ENV=os.environ,
|
||||
UNIX_TIME=int(time()),
|
||||
TIMESTAMP=int(time()),
|
||||
UNIX_TIME="$TIMESTAMP", # deprecated
|
||||
BUILD_DIR=os.path.join("$PROJECT_BUILD_DIR", "$PIOENV"),
|
||||
BUILD_SRC_DIR=os.path.join("$BUILD_DIR", "src"),
|
||||
BUILD_TEST_DIR=os.path.join("$BUILD_DIR", "test"),
|
||||
|
@ -67,7 +67,6 @@ class MeasurementProtocol:
|
||||
def to_payload(self):
|
||||
return {
|
||||
"client_id": self.client_id,
|
||||
"user_id": f"cid:{self.client_id}",
|
||||
"non_personalized_ads": True,
|
||||
"user_properties": self._user_properties,
|
||||
"events": self._events,
|
||||
|
@ -13,13 +13,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import functools
|
||||
import math
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
import click
|
||||
|
||||
@ -168,10 +168,14 @@ def items_in_list(needle, haystack):
|
||||
return set(needle) & set(haystack)
|
||||
|
||||
|
||||
def get_timestamp(utc=True):
|
||||
return datetime.datetime.now(datetime.timezone.utc if utc else None).timestamp()
|
||||
|
||||
|
||||
def parse_datetime(datestr):
|
||||
if "T" in datestr and "Z" in datestr:
|
||||
return datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%SZ")
|
||||
return datetime.strptime(datestr)
|
||||
return datetime.datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%SZ")
|
||||
return datetime.datetime.strptime(datestr)
|
||||
|
||||
|
||||
def merge_dicts(d1, d2, path=None):
|
||||
|
@ -469,7 +469,7 @@ def test_custom_project_tools(
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(PROJECT_CONFIG_TPL)
|
||||
spec = "platformio/tool-openocd"
|
||||
spec = "platformio/tool-openocd @ ^2"
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd,
|
||||
["-d", str(project_dir), "-e", "devkit", "-t", spec],
|
||||
@ -503,7 +503,7 @@ def test_custom_project_tools(
|
||||
|
||||
# check saved deps
|
||||
assert config.get("env:devkit", "platform_packages") == [
|
||||
"platformio/tool-openocd@^2.1100.211028",
|
||||
"platformio/tool-openocd@^2",
|
||||
]
|
||||
|
||||
# install tool without saving to config
|
||||
@ -518,7 +518,7 @@ def test_custom_project_tools(
|
||||
PackageSpec("tool-openocd@2.1100.211028"),
|
||||
]
|
||||
assert config.get("env:devkit", "platform_packages") == [
|
||||
"platformio/tool-openocd@^2.1100.211028",
|
||||
"platformio/tool-openocd@^2",
|
||||
]
|
||||
|
||||
# unknown tool
|
||||
|
@ -313,7 +313,7 @@ def test_custom_project_tools(
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(PROJECT_CONFIG_TPL)
|
||||
spec = "platformio/tool-openocd"
|
||||
spec = "platformio/tool-openocd@^2"
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd,
|
||||
["-d", str(project_dir), "-e", "devkit", "-t", spec],
|
||||
@ -329,7 +329,7 @@ def test_custom_project_tools(
|
||||
assert not os.path.exists(config.get("platformio", "platforms_dir"))
|
||||
# check saved deps
|
||||
assert config.get("env:devkit", "platform_packages") == [
|
||||
"platformio/tool-openocd@^2.1100.211028",
|
||||
"platformio/tool-openocd@^2",
|
||||
]
|
||||
# uninstall
|
||||
result = clirunner.invoke(
|
||||
|
Reference in New Issue
Block a user