gi-glib-2.0.29: GLib bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.GLib.Structs.TimeVal

Contents

- Exported types
- Methods
  - add
  - fromIso8601
  - toIso8601
- Properties
  - tvSec
  - tvUsec

Description

Represents a precise time, with seconds and microseconds.

Similar to the struct timeval returned by the `gettimeofday()` UNIX system call.

GLib is attempting to unify around the use of 64-bit integers to represent microsecond-precision time. As such, this type will be removed from a future version of GLib. A consequence of using `glong` for `tv_sec` is that on 32-bit systems `GTimeVal` is subject to the year 2038 problem.

Synopsis

- newtype TimeVal = TimeVal (ManagedPtr TimeVal)
- newZeroTimeVal :: MonadIO m => m TimeVal
- timeValAdd :: (HasCallStack, MonadIO m) => TimeVal -> CLong -> m ()
- timeValFromIso8601 :: (HasCallStack, MonadIO m) => Text -> m (Bool, TimeVal)
- timeValToIso8601 :: (HasCallStack, MonadIO m) => TimeVal -> m (Maybe Text)
- getTimeValTvSec :: MonadIO m => TimeVal -> m CLong
- setTimeValTvSec :: MonadIO m => TimeVal -> CLong -> m ()
- getTimeValTvUsec :: MonadIO m => TimeVal -> m CLong
- setTimeValTvUsec :: MonadIO m => TimeVal -> CLong -> m ()

# Exported types

newtype TimeVal Source #

Memory-managed wrapper type.

Constructors

TimeVal (ManagedPtr TimeVal) |

#### Instances

Instances details

Eq TimeVal Source # |
Instance details Defined in GI.GLib.Structs.TimeVal Methods (==) :: TimeVal -> TimeVal -> Bool Source # (/=) :: TimeVal -> TimeVal -> Bool Source #
BoxedPtr TimeVal Source # |
Instance details Defined in GI.GLib.Structs.TimeVal Methods boxedPtrCopy :: TimeVal -> IO TimeVal Source # boxedPtrFree :: TimeVal -> IO () Source #
CallocPtr TimeVal Source # |
Instance details Defined in GI.GLib.Structs.TimeVal Methods boxedPtrCalloc :: IO (Ptr TimeVal) Source #
ManagedPtrNewtype TimeVal Source # |
Instance details Defined in GI.GLib.Structs.TimeVal Methods toManagedPtr :: TimeVal -> ManagedPtr TimeVal Source #
tag ~ 'AttrSet => Constructible TimeVal tag Source # |
Instance details Defined in GI.GLib.Structs.TimeVal Methods new :: MonadIO m => (ManagedPtr TimeVal -> TimeVal) -> [AttrOp TimeVal tag] -> m TimeVal Source #

newZeroTimeVal :: MonadIO m => m TimeVal Source #

Construct a `TimeVal` struct initialized to zero.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

add, toIso8601.

#### Getters

None.

#### Setters

None.

## add

timeValAdd Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> TimeVal | `time_`: a `TimeVal`
-> CLong | `microseconds`: number of microseconds to add to `time`
-> m () |

Deprecated: (Since version 2.62)t`TimeVal` is not year-2038-safe. Use `guint64` for representing microseconds since the epoch, or use `DateTime`.

Adds the given number of microseconds to `time_`. `microseconds` can also be negative to decrease the value of `time_`.

## fromIso8601

timeValFromIso8601 Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `isoDate`: an ISO 8601 encoded date string
-> m (Bool, TimeVal) | Returns: `True` if the conversion was successful.

Deprecated: (Since version 2.62)t`TimeVal` is not year-2038-safe. Use `dateTimeNewFromIso8601` instead.

Converts a string containing an ISO 8601 encoded date and time to a `TimeVal` and puts it into `time_`.

`isoDate` must include year, month, day, hours, minutes, and seconds. It can optionally include fractions of a second and a time zone indicator. (In the absence of any time zone indication, the timestamp is assumed to be in local time.)

Any leading or trailing space in `isoDate` is ignored.

This function was deprecated, along with `TimeVal` itself, in GLib 2.62. Equivalent functionality is available using code like: > >GDateTime *dt = g_date_time_new_from_iso8601 (iso8601_string, NULL); >gint64 time_val = g_date_time_to_unix (dt); >g_date_time_unref (dt);

Since: 2.12

## toIso8601

timeValToIso8601 Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> TimeVal | `time_`: a `TimeVal`
-> m (Maybe Text) | Returns: a newly allocated string containing an ISO 8601 date, or `Nothing` if `time_` was too large

Deprecated: (Since version 2.62)t`TimeVal` is not year-2038-safe. Use g_date_time_format_iso8601(dt) instead.

Converts `time_` into an RFC 3339 encoded string, relative to the Coordinated Universal Time (UTC). This is one of the many formats allowed by ISO 8601.

ISO 8601 allows a large number of date/time formats, with or without punctuation and optional elements. The format returned by this function is a complete date and time, with optional punctuation included, the UTC time zone represented as "Z", and the `tvUsec` part included if and only if it is nonzero, i.e. either "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ".

This corresponds to the Internet date/time format defined by RFC 3339, and to either of the two most-precise formats defined by the W3C Note Date and Time Formats. Both of these documents are profiles of ISO 8601.

Use `dateTimeFormat` or `g_strdup_printf()` if a different variation of ISO 8601 format is required.

If `time_` represents a date which is too large to fit into a `struct tm`, `Nothing` will be returned. This is platform dependent. Note also that since `GTimeVal` stores the number of seconds as a `glong`, on 32-bit systems it is subject to the year 2038 problem. Accordingly, since GLib 2.62, this function has been deprecated. Equivalent functionality is available using: > >GDateTime *dt = g_date_time_new_from_unix_utc (time_val); >iso8601_string = g_date_time_format_iso8601 (dt); >g_date_time_unref (dt);

The return value of `timeValToIso8601` has been nullable since GLib 2.54; before then, GLib would crash under the same conditions.

Since: 2.12

# Properties

## tvSec

seconds

getTimeValTvSec :: MonadIO m => TimeVal -> m CLong Source #

Get the value of the “`tv_sec`” field. When overloading is enabled, this is equivalent to

    get timeVal #tvSec

setTimeValTvSec :: MonadIO m => TimeVal -> CLong -> m () Source #

Set the value of the “`tv_sec`” field. When overloading is enabled, this is equivalent to

    set timeVal [ #tvSec := value ]

## tvUsec

microseconds

getTimeValTvUsec :: MonadIO m => TimeVal -> m CLong Source #

Get the value of the “`tv_usec`” field. When overloading is enabled, this is equivalent to

    get timeVal #tvUsec

setTimeValTvUsec :: MonadIO m => TimeVal -> CLong -> m () Source #

Set the value of the “`tv_usec`” field. When overloading is enabled, this is equivalent to

    set timeVal [ #tvUsec := value ]