[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] Time conversion functions
From: |
xypron |
Subject: |
Re: [Help-glpk] Time conversion functions |
Date: |
Thu, 20 Nov 2008 23:42:42 -0800 (PST) |
Hello Andrew,
please, find in the appendix a description of the functions that I
implemented, which cover most of the whishis mailed in this thread.
What remains to be done is to correctly handle calendar weeks.
ISO 8601 defines a week date.
Weeks start with Monday = 1 and a ends with Sunday = 7.
The first week of a year is the week that contains the first Thursday of a
year.
C99 function strftime at least as implemented by Microsoft does not adher to
ISO 8601 hence we will have to replace it.
Function timegm is not present on all POSIX systems hence it might make
sense to implement our own function to convert a tm structure to a time.
Best regards
Xypron
Time functions
==============
now()
returns a numeric with the current time as seconds since
1970-01-01T00:00:00.
Example
display now();
gmtime( t, fmt)
returns a symbol with a timestamp in the time of timezone UTC+0000.
Numeric t specifies the time as seconds since 1970-01-01T00:00:00.
Symbol format specifies the format of the timestamp.
The format fmt is a concatenation of format strings starting with '%'. At
least the following are supported:
%d day
%F expands to %Y-%m-%d - not implemented yet
%H hour
%M minute
%m calendar month
%S second
%T expands to %H:%M:%S - no implemented yet
%V year according to calendar week - to be implemented
%W calendar week - current implementation is flawed
correct implementation: a calendar week starts on monday and belongs to
the year
containing the thursday of the week.
%w weekday, 0 = sunday, 6 = saturday - should be changed to 1 = monday, 7 =
sunday
%Y year
All characters that are not part of a format string are copied to the
timestamp.
Example:
display gmtime( 1226766130, "%Y-%m-%dT%H:%M:%SZ");
will output
'2008-11-15T16:22:10Z'
localtime( t, fmt)
returns a symbol with a timestamp in the time of the local timezone.
Numeric t specifies the time as seconds since 1970-01-01T00:00:00.
Symbol fmt specifies the format of the timestamp.
The format fmt is a concatenation of format strings starting with '%'. At
least the following are supported:
%d day
%F expands to %Y-%m-%d - not implemented yet
%H hour
%M minute
%m calendar month
%S second
%T expands to %H:%M:%S - no implemented yet
%V year according to calendar week - to be implemented
%W calendar week - current implementation is flawed
correct implementation: a calendar week starts on monday and belongs to
the year
containing the thursday of the week.
%w weekday, 0 = sunday, 6 = saturday - should be changed to 1 = monday, 7 =
sunday
%Y year
All characters that are not part of a format string are copied to the
timestamp.
Example:
display localtime( 1226766130, "%Y-%m-%dT%H:%M:%S");
will output
'2008-11-15T17:22:10'
for a user in timezone Europe/Berlin.
str2time( str, fmt)
returns a numeric with a time as seconds since 1970-01-01T00:00:00.
Symbol str is the timestamp t be parsed.
Symbol fmt specifies the format of the timestamp.
The format fmt is a concatenation of format strings starting with '%'.
%d day, 01-31
%F expands to %Y-%m-%d
%H hour, 00-23
%M minute, 00-59
%m month, 01-12
%S second, 00-61
%T expands to %H:%M:%S
%z matches offset
either Z
or signed 2 digit offset, -23 - +23
or signed 4 digit offset, -2359 - +2359
or signed 4 digit offset, -23:59 - +23:59
All characters that are not part of a format string are expected in the
timestamp.
Example
display str2time( '2008-11-15T13:22:10+0300', "%Y-%m-%dT%H:%M:%S%z");
will output
1226766130.
dur2str( dur, fmt)
returns a symbol with a duration.
Numeric dur is the duration in seconds.
Symbol fmt is the format of the duration symbol to be created.
The format fmt is a concatenation of format strings starting with '%'.
%D days (5 digits, leading 0)
%d days
%H hours
%M minutes
%S seconds
%S. seconds.centiseconds
%s sign (+ or -)
All characters that are not part of a format string are copied to the
duration symbol.
Example
display dur2str( -23454589.326, "P%dDT%HH%MM%S.S");
displays
'P271DT11H09M49.33S'.
str2dur( str, fmt)
returns a duration in seconds.
Symbol str is the string to be parsed.
Symbol fmt is the format of the duration symbol.
The format fmt is a concatenation of format strings starting with '%'.
%D days (5 digits, leading 0)
%d days
%H hours
%M minutes
%S seconds
All characters that are not part of a format string are expected in the
duration symbol.
The format fmt is a concatenation of format strings starting with '%'.
%d days
%H hours
%M minutes
%m months
%S seconds
%W weeks
%Y years
Single characters except % are matched one to one.
Example
display str2dur( 'P271DT11H09M49S', "P%dDT%HH%MM%SS");
displays
23454589.
--
View this message in context:
http://www.nabble.com/Time-conversion-functions-tp20549985p20616499.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.
- Re: [Help-glpk] Time conversion functions, (continued)
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/19
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/20
- RE: [Help-glpk] Time conversion functions, Meketon, Marc, 2008/11/20
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/20
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- RE: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- RE: [Help-glpk] Time conversion functions, Meketon, Marc, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Maurice Diamantini, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/21
- Re: [Help-glpk] Time conversion functions,
xypron <=
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/23
- Message not available
- Message not available
- Message not available
- Message not available
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/24
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/25