Skip to content

Commit e1edabd

Browse files
committed
alif/modtime: Implement the rest of the time module.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 6b11c51 commit e1edabd

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

ports/alif/modtime.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/mphal.h"
28+
#include "shared/timeutils/timeutils.h"
29+
30+
// Return the localtime as an 8-tuple.
31+
static mp_obj_t mp_time_localtime_get(void) {
32+
mp_timestamp_t s = mp_hal_time_get(NULL);
33+
timeutils_struct_time_t tm;
34+
timeutils_seconds_since_epoch_to_struct_time(s, &tm);
35+
mp_obj_t tuple[8] = {
36+
mp_obj_new_int(tm.tm_year),
37+
mp_obj_new_int(tm.tm_mon),
38+
mp_obj_new_int(tm.tm_mday),
39+
mp_obj_new_int(tm.tm_hour),
40+
mp_obj_new_int(tm.tm_min),
41+
mp_obj_new_int(tm.tm_sec),
42+
mp_obj_new_int(tm.tm_wday),
43+
mp_obj_new_int(tm.tm_yday),
44+
};
45+
return mp_obj_new_tuple(8, tuple);
46+
}
47+
48+
// Return the number of seconds since the Epoch.
49+
static mp_obj_t mp_time_time_get(void) {
50+
return mp_obj_new_int_from_uint(mp_hal_time_get(NULL));
51+
}

ports/alif/mpconfigport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
#define MICROPY_PY_OS_UNAME (1)
120120
#define MICROPY_PY_OS_URANDOM (1)
121121
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (se_services_rand64())
122-
#define MICROPY_PY_TIME (1)
122+
#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1)
123+
#define MICROPY_PY_TIME_TIME_TIME_NS (1)
124+
#define MICROPY_PY_TIME_INCLUDEFILE "ports/alif/modtime.c"
123125
#define MICROPY_PY_MACHINE (1)
124126
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/alif/modmachine.c"
125127
#define MICROPY_PY_MACHINE_RESET (1)

0 commit comments

Comments
 (0)