[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Time conversion functions

From: Andrew Makhorin
Subject: Re: [Help-glpk] Time conversion functions
Date: Tue, 18 Nov 2008 16:09:21 +0300

Hi Xypron,

> currently I am using GLPK mainly for scheduling problems. Here the data
> often contains references to time. The GMPL language does not provide any
> functions to convert timestamps to numbers and numbers back to
> timestamps.

> I propose to add the following functions:

> now() returns the number of seconds since 1970
> Knowing the current time is useful as scheduling should not place
> production in the past.

> str2time( str, fmt ) converts a timestamp str given in format fmt to
> number of seconds since 1970
> e.g. str2time( "2008-11-15T13:22:10+0300", "%Y-%m-%dT%H:%M:%S%z");
> The time formats of RFC 3339 should be supported (a subset of ISO 8601).
> The format strings should be a subset of those used by the strptime()
> function in library GLIBC.
> Conversion of non local time will have to rely on availability of either
> function timegm() (or _mkgmtime for Microsoft Visual C) or structure
> element tm->tm_gmtoff.

> localtime( num, fmt ) converts a number to a timestamp in local time
> e.g. localtime( now(), "%Y-%m-%dT%H:%M:%S%")
> a possible output would be 
> 2008-11-15T17:22:10
> The format strings should be those used by the strftime() function in
> C99.

> gmtime( num, fmt ) converts a number to a timestamp in global time
> e.g. gmtime( now(), "%Y-%m-%dT%H:%M:%S%Z")
> a possibel output would be
> 2008-11-15T16:22:10
> The format strings should be those used by the strftime() function in
> C99.

> I have implemented the necessary changes to glpk-4.33 which can be found
> at

> new files are:
> include/glptime.h
> src/glptime.c

> changed files are:
> include/glpmpl.h
> src/
> src/glpmpl01.c
> src/glpmpl03.c
> w32/Makefile*
> w32/config_VC9
> w64/Makefile*
> w64/config_VC9

Thank you for your proposal.

In fact, inclusion of date/time functions in mathprog would be very
useful. However, it seems to me that using timezone info is an
unnecessary feature.

I suggest to implement two date/time formats. One is the number
of seconds since 1970-01-01 00:00:00 represented as a floating-point
number suitable for arithmetic calculations, and another is a
character string suitable for external representation. Then there
should be two functions to convert between these two formats, and
probably some functions to access components of the timestamp like
year, month, etc.

Andrew Makhorin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]