MrpTime

MrpTime — represents date and time.

Functions

mrptime mrp_time_current_time ()
mrptime mrp_time_compose ()
gboolean mrp_time_decompose ()
mrptime mrp_time_from_string ()
gchar * mrp_time_to_string ()
mrptime mrp_time_from_msdate_string ()
mrptime mrp_time_align_day ()
mrptime mrp_time_align_prev ()
mrptime mrp_time_align_next ()
gint mrp_time_day_of_week ()
gint mrp_time_week_number ()
const gchar * mrp_time_day_name ()
const gchar * mrp_time_month_name ()
const gchar * mrp_time_month_name_initial ()
gchar * mrp_time_format ()
gchar * mrp_time_format_locale ()
void mrp_time_debug_print ()
GParamSpec * mrp_param_spec_time ()
mrptime mrp_time_from_tm ()
MrpTime * mrp_time2_new ()
void mrp_time2_free ()
void mrp_time2_set_date ()
void mrp_time2_set_time ()
void mrp_time2_get_date ()
void mrp_time2_get_time ()
void mrp_time2_add_years ()
void mrp_time2_add_months ()
void mrp_time2_add_days ()
void mrp_time2_add_seconds ()
void mrp_time2_add_minutes ()
void mrp_time2_add_hours ()
void mrp_time2_subtract_years ()
void mrp_time2_subtract_months ()
void mrp_time2_subtract_days ()
void mrp_time2_subtract_hours ()
void mrp_time2_subtract_minutes ()
void mrp_time2_subtract_seconds ()
void mrp_time2_debug_print ()
gboolean mrp_time2_set_from_string ()
gchar * mrp_time2_to_string ()
void mrp_time2_set_epoch ()
time_t mrp_time2_get_epoch ()
const gchar * mrp_time2_get_day_name ()
const gchar * mrp_time2_get_month_name ()
const gchar * mrp_time2_get_month_initial ()
gint mrp_time2_get_week_number ()
void mrp_time2_align_prev ()
void mrp_time2_align_next ()
void mrp_time2_copy ()
void mrp_time2_clear ()
gint mrp_time2_compare ()

Types and Values

typedef mrptime
#define MRP_TIME_INVALID
#define MRP_TIME_MIN
#define MRP_TIME_MAX
enum MrpTimeUnit
  MrpTime

Includes

#include <libplanner/mrp-time.h>

Description

Two APIs co-exists: Calendar time with mrptime and broken-down time with MrpTime.

libplanner does not use MrpTime.

ISO 8601 representation is done in the basic format. Less separators are used: 20150101T000000Z for 2015-01-01T00:00:00Z.

Functions

mrp_time_current_time ()

mrptime
mrp_time_current_time (void);

Retrieves the current time as an mrptime value.

Returns

Current time.


mrp_time_compose ()

mrptime
mrp_time_compose (gint year,
                  gint month,
                  gint day,
                  gint hour,
                  gint minute,
                  gint second);

Composes an mrptime value from the separate components.

Parameters

year

the year

 

month

the month

 

day

the day

 

hour

the hour

 

minute

the minute

 

second

the second

 

Returns

an mrptime value.


mrp_time_decompose ()

gboolean
mrp_time_decompose (mrptime t,
                    gint *year,
                    gint *month,
                    gint *day,
                    gint *hour,
                    gint *minute,
                    gint *second);

Splits up an mrptime value into its components.

Parameters

t

an mrptime value to decompose

 

year

location to store year, or NULL

 

month

location to store month, or NULL

 

day

location to store day, or NULL

 

hour

location to store hour, or NULL

 

minute

location to store minute, or NULL

 

second

location to store second, or NULL

 

Returns

TRUE on success.


mrp_time_from_string ()

mrptime
mrp_time_from_string (const gchar *str,
                      GError **err);

Parses an ISO8601 time string and converts it to an mrptime.

Parameters

str

a string with a time, ISO8601 format

 

err

Location to store error, or NULL

 

Returns

Converted time value.


mrp_time_to_string ()

gchar *
mrp_time_to_string (mrptime t);

Converts a time value to an ISO8601 string.

Parameters

t

an mrptime time

 

Returns

Allocated string that needs to be freed.


mrp_time_from_msdate_string ()

mrptime
mrp_time_from_msdate_string (const gchar *str);
Unimplemented.

Parameters

str

A string.

 

Returns

an mrptime


mrp_time_align_day ()

mrptime
mrp_time_align_day (mrptime t);

Aligns a time value to the start of the day.

Parameters

t

an mrptime value

 

Returns

Aligned value.


mrp_time_align_prev ()

mrptime
mrp_time_align_prev (mrptime t,
                     MrpTimeUnit unit);

Align t to the previous unit .

Parameters

t

an mrptime value

 

unit

an MrpTimeUnit

 

Returns

Aligned value.


mrp_time_align_next ()

mrptime
mrp_time_align_next (mrptime t,
                     MrpTimeUnit unit);

Align t to the next unit .

Parameters

t

an mrptime value

 

unit

an MrpTimeUnit

 

Returns

Aligned value.


mrp_time_day_of_week ()

gint
mrp_time_day_of_week (mrptime t);

Retrieves the day of week of the specified time.

Parameters

t

an mrptime value

 

Returns

The day of week, in the range 0 to 6, where Sunday is 0.


mrp_time_week_number ()

gint
mrp_time_week_number (mrptime t);

Retrieves the week number of the specified time.

Parameters

t

an mrptime value

 

Returns

ISO 8601 week number.


mrp_time_day_name ()

const gchar *
mrp_time_day_name (mrptime t);

Retrieves the name of the day of the specified time.

Parameters

t

an mrptime value

 

Returns

The day name, which is static data.


mrp_time_month_name ()

const gchar *
mrp_time_month_name (mrptime t);

Retrieves the name of the month of the specified time.

Parameters

t

an mrptime value

 

Returns

The month name, which is static data.


mrp_time_month_name_initial ()

const gchar *
mrp_time_month_name_initial (mrptime t);

Retrieves the initial letter for the month of the specified time.

Parameters

t

an mrptime value

 

Returns

The initial, which is static data.


mrp_time_format ()

gchar *
mrp_time_format (const gchar *format,
                 mrptime t);

Formats a string with time values.

The following format codes are allowed:

  • %a: the abbreviated weekday name (Mon, Tue, ...)

  • %A: the full weekday name (Monday, Tuesday, ...)

  • %b: the abbreviated month name (Jan, Feb, ...)

  • %B: the full month name (January, February, ...)

  • %d: the day of the month (01 - 31).

  • %e: the day of the month (1 - 31).

  • %H: the hour using a 24-hour clock (00 - 23).

  • %I: the hour using a 12-hour clock (01 - 12).

  • %j: the day of the year (001 - 366).

  • %k: the hour using a 24-hour clock (0 to 23).

  • %l: the hour using a 12-hour clock (1 - 12).

  • %m: the month number (01 to 12).

  • %M: the minute (00 - 59).

  • %p: either 'AM' or 'PM' according to the given time value.

  • %P: like %p but in lowercase.

  • %R: the time in 24 hour notation (%H:%M).

  • %S: the second (00 - 61).

  • %U: the week number, (1 - 53), starting with the first Sunday as the first day of week 1.

  • %W: the week number, (1 - 53), starting with the first Monday as the first day of week 1.

  • %y: the year without a century (range 00 to 99).

  • %Y: the year including the century.

Parameters

format

format string

 

t

an mrptime value

 

Returns

Newly created string that needs to be freed.


mrp_time_format_locale ()

gchar *
mrp_time_format_locale (mrptime t);

Formats a string with time values. For format is the preferred for the current locale.

Parameters

t

an mrptime value

 

Returns

Newly created string that needs to be freed.


mrp_time_debug_print ()

void
mrp_time_debug_print (mrptime t);

Prints the time on stdout, for debugging purposes.

Parameters

t

an mrptime

 

mrp_param_spec_time ()

GParamSpec *
mrp_param_spec_time (const gchar *name,
                     const gchar *nick,
                     const gchar *blurb,
                     GParamFlags flags);

Convenience function for creating a GParamSpec carrying an mrptime value.

Parameters

name

name of the property

 

nick

nick for the propery

 

blurb

blurb for the property

 

flags

flags

 

Returns

Newly created GParamSpec.


mrp_time_from_tm ()

mrptime
mrp_time_from_tm (struct tm *tm);

Converts a struct tm value to an mrptime value.

Parameters

tm

pointer to a struct tm time value

 

Returns

mrptime value.


mrp_time2_new ()

MrpTime *
mrp_time2_new (void);

MrpTime constructor.

Returns

A newly created MrpTime.


mrp_time2_free ()

void
mrp_time2_free (MrpTime *t);

MrpTime destructor.

Parameters

t

an MrpTime.

 

mrp_time2_set_date ()

void
mrp_time2_set_date (MrpTime *t,
                    gint year,
                    gint month,
                    gint day);

Set t date.

Parameters

t

an MrpTime

 

year

year

 

month

month

 

day

day

 

mrp_time2_set_time ()

void
mrp_time2_set_time (MrpTime *t,
                    gint hour,
                    gint min,
                    gint sec);

Set t time.

Parameters

t

an MrpTime

 

hour

hour

 

min

min

 

sec

sec

 

mrp_time2_get_date ()

void
mrp_time2_get_date (MrpTime *t,
                    gint *year,
                    gint *month,
                    gint *day);

Get t time.

Parameters

t

an MrpTime

 

year

year

 

month

month

 

day

day

 

mrp_time2_get_time ()

void
mrp_time2_get_time (MrpTime *t,
                    gint *hour,
                    gint *min,
                    gint *sec);

Get t time.

Parameters

t

an MrpTime

 

hour

hour

 

min

min

 

sec

sec

 

mrp_time2_add_years ()

void
mrp_time2_add_years (MrpTime *t,
                     gint years);

Add years to t .

Parameters

t

an MrpTime

 

years

years

 

mrp_time2_add_months ()

void
mrp_time2_add_months (MrpTime *t,
                      gint months);

Add months to t .

Parameters

t

an MrpTime

 

months

months

 

mrp_time2_add_days ()

void
mrp_time2_add_days (MrpTime *t,
                    gint days);

Add days to t .

Parameters

t

an MrpTime

 

days

days

 

mrp_time2_add_seconds ()

void
mrp_time2_add_seconds (MrpTime *t,
                       gint64 secs);

Add secs to t .

Parameters

t

an MrpTime

 

secs

seconds

 

mrp_time2_add_minutes ()

void
mrp_time2_add_minutes (MrpTime *t,
                       gint64 mins);

Add mins to t .

Parameters

t

an MrpTime

 

mins

minutes

 

mrp_time2_add_hours ()

void
mrp_time2_add_hours (MrpTime *t,
                     gint64 hours);

Add hours to t .

Parameters

t

an MrpTime

 

hours

hours

 

mrp_time2_subtract_years ()

void
mrp_time2_subtract_years (MrpTime *t,
                          gint years);

Subtract years from t .

Parameters

t

an MrpTime

 

years

years

 

mrp_time2_subtract_months ()

void
mrp_time2_subtract_months (MrpTime *t,
                           gint months);

Subtract months from t .

Parameters

t

an MrpTime

 

months

months

 

mrp_time2_subtract_days ()

void
mrp_time2_subtract_days (MrpTime *t,
                         gint days);

Subtract days from t .

Parameters

t

an MrpTime

 

days

days

 

mrp_time2_subtract_hours ()

void
mrp_time2_subtract_hours (MrpTime *t,
                          gint64 hours);

Subtract hours from t .

Parameters

t

an MrpTime

 

hours

hours

 

mrp_time2_subtract_minutes ()

void
mrp_time2_subtract_minutes (MrpTime *t,
                            gint64 mins);

Subtract mins from t .

Parameters

t

an MrpTime

 

mins

minutes

 

mrp_time2_subtract_seconds ()

void
mrp_time2_subtract_seconds (MrpTime *t,
                            gint64 secs);

Subtract secs from t .

Parameters

t

an MrpTime

 

secs

seconds

 

mrp_time2_debug_print ()

void
mrp_time2_debug_print (MrpTime *t);

Prints the time on stdout, for debugging purposes.

Parameters

t

an MrpTime

 

mrp_time2_set_from_string ()

gboolean
mrp_time2_set_from_string (MrpTime *t,
                           const gchar *str);

Set t according to str .

Three formats are recognized "yyyymmddTHHMMSS", "yyyymmddTHHMMSSZ", and "yyyymmdd". The last is a date, the time part of t is not modified. mrp_time2_set_from_string(t, "20041231") is not equivalent to mrp_time2_set_from_string(t, "20041231T000000Z").

Parameters

t

an MrpTime

 

str

a string

 

Returns

TRUE on success, FALSE on failure


mrp_time2_to_string ()

gchar *
mrp_time2_to_string (MrpTime *t);

Build an ISO 8601 representation for t .

Parameters

t

an MrpTime

 

Returns

a string


mrp_time2_set_epoch ()

void
mrp_time2_set_epoch (MrpTime *t,
                     time_t epoch);

Set t according to the calendar time epoch .

Parameters

t

an MrpTime

 

epoch

epoch

 

mrp_time2_get_epoch ()

time_t
mrp_time2_get_epoch (MrpTime *t);

Return the calendar time corresponding to t .

Parameters

t

an MrpTime

 

Returns

epoch


mrp_time2_get_day_name ()

const gchar *
mrp_time2_get_day_name (MrpTime *t);

Retrieves the name of the day of the specified time.

Parameters

t

an MrpTime

 

Returns

static data


mrp_time2_get_month_name ()

const gchar *
mrp_time2_get_month_name (MrpTime *t);

Retrieves the name of the month of the specified time.

Parameters

t

an MrpTime

 

Returns

static data


mrp_time2_get_month_initial ()

const gchar *
mrp_time2_get_month_initial (MrpTime *t);

Retrieves the initial letter for the month of the specified time.

Parameters

t

an MrpTime

 

Returns

static data


mrp_time2_get_week_number ()

gint
mrp_time2_get_week_number (MrpTime *t,
                           gint *year);

Retrieves the week number of the specified time.

Parameters

t

an MrpTime

 

year

the year

 

Returns

ISO 8601 week number


mrp_time2_align_prev ()

void
mrp_time2_align_prev (MrpTime *t,
                      MrpTimeUnit unit);

Align t to the previous unit .

Parameters

t

an MrpTime

 

unit

an MrpTimeUnit

 

mrp_time2_align_next ()

void
mrp_time2_align_next (MrpTime *t,
                      MrpTimeUnit unit);

Align t to the next unit .

Parameters

t

an MrpTime

 

unit

an MrpTimeUnit

 

mrp_time2_copy ()

void
mrp_time2_copy (MrpTime *dst,
                MrpTime *src);

Copy an MrpTime.

Parameters

dst

an MrpTime

 

src

an MrpTime

 

mrp_time2_clear ()

void
mrp_time2_clear (MrpTime *t);

Clear an MrpTime.

Parameters

t

an MrpTime

 

mrp_time2_compare ()

gint
mrp_time2_compare (MrpTime *t1,
                   MrpTime *t2);

Compare two MrpTime.

Parameters

t1

an MrpTime

 

t2

an MrpTime

 

Returns

-1, 0 or 1.

Types and Values

mrptime

typedef long mrptime;

Corresponds to the standard C time_t type.


MRP_TIME_INVALID

#define MRP_TIME_INVALID 0

Represents an invalid mrptime value.


MRP_TIME_MIN

#define MRP_TIME_MIN 0

Represents the minimum value for mrptime.


MRP_TIME_MAX

#define MRP_TIME_MAX 2147483647

Represents the maximum value for mrptime.


enum MrpTimeUnit

Time granularity meaningful to humans.

Members

MRP_TIME_UNIT_NONE

none.

 

MRP_TIME_UNIT_YEAR

year.

 

MRP_TIME_UNIT_HALFYEAR

half year.

 

MRP_TIME_UNIT_QUARTER

quarter.

 

MRP_TIME_UNIT_MONTH

month.

 

MRP_TIME_UNIT_WEEK

week.

 

MRP_TIME_UNIT_DAY

day.

 

MRP_TIME_UNIT_HALFDAY

half day.

 

MRP_TIME_UNIT_TWO_HOURS

two hours.

 

MRP_TIME_UNIT_HOUR

hour.

 

MrpTime

typedef struct _MrpTime MrpTime;

Broken-down time. A kind of standard C struct tm.