[PATCH 2/2] Set system date and time with our own function

Vratislav Podzimek vpodzime at redhat.com
Tue Jul 30 11:16:22 UTC 2013


On Tue, 2013-07-30 at 11:44 +0200, Vratislav Podzimek wrote:

> +def set_system_date_time(year=None, month=None, day=None, hour=None, minute=None,
> +                         second=None, utc=False):
> +    """
> +    Set system date and time given by the parameters as numbers. If some
> +    parameter is missing or None, the current system date/time field is used
> +    instead (i.e. the value is not changed by this function).
> +
> +    :type year, month, ..., second: int
> +    :param utc: wheter the other parameters specify UTC or local time
> +    :type utc: bool
> +
> +    """
> +
> +    # get the right values
> +    utc = 0 if utc else 1
> +    year = year or datetime.datetime.now().year
> +    month = month or datetime.datetime.now().month
> +    day = day or datetime.datetime.now().day
> +    hour = hour or datetime.datetime.now().hour
> +    minute = minute or datetime.datetime.now().minute
> +    second = second or datetime.datetime.now().second
> +
> +    # struct fields -> year, month, day, hour, minute, second, week_day, year_day, utc
The last field is 'local', that's why the inversion and bool-to-int
conversion is done in the beginning of the function. I'll fix the
comment and also rename the 'utc' variable to 'local'. Fixing locally.

> +    time_struct = time.struct_time((year, month, day, hour, minute, second, 0, 0, utc))
> +    set_system_time(int(time.mktime(time_struct)))

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list