-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] add time_stamp
function and stdlib_time
module: get formatted now time information?
#464
Comments
time_stamp
function and stdlib_time
module: get now time formatted information?time_stamp
function and stdlib_time
module: get formatted now time information?
The codes of John Burkardt all contain a timestamp subroutine (GPL-licensed) with fixed format: subroutine timestamp()subroutine timestamp ( )
!*****************************************************************************80
!
!! TIMESTAMP prints the current YMDHMS date as a time stamp.
!
! Example:
!
! 31 May 2001 9:45:54.872 AM
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 18 May 2013
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! None
!
implicit none
character ( len = 8 ) ampm
integer ( kind = 4 ) d
integer ( kind = 4 ) h
integer ( kind = 4 ) m
integer ( kind = 4 ) mm
character ( len = 9 ), parameter, dimension(12) :: month = (/ &
'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', &
'September', 'October ', 'November ', 'December ' /)
integer ( kind = 4 ) n
integer ( kind = 4 ) s
integer ( kind = 4 ) values(8)
integer ( kind = 4 ) y
call date_and_time ( values = values )
y = values(1)
m = values(2)
d = values(3)
h = values(5)
n = values(6)
s = values(7)
mm = values(8)
if ( h < 12 ) then
ampm = 'AM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h < 12 ) then
ampm = 'PM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Midnight'
else
ampm = 'AM'
end if
end if
end if
write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &
d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )
return
end On the other hand the function fmtdate(values,format) RESULT (timestr)
Here are some options from other languages:
Some open issues to discuss are:
|
Perhaps this is a bad idea, but I wonder if there is any advantage to write into the format string directly? integer :: dat(8)
call date_and_time(values=dat)
write(*,fmtdate(dat))
! vs
write(*,'(A)') datestr(dat) |
Somewhat related is #106. Rather than implementing a specific (fixed-format) time stamp, I recommend simply providing a binding to C The Forlab implementation looks like it was adapted from John Burkardt's. |
This comment has been minimized.
This comment has been minimized.
Absolutely. Adopting the same interface is okay, I believe, but you have to respect the license when it comes to the implementation. That's why looking too closely at GPL code for the standard library isn't such a good idea IMO. The standard library is aiming for MIT or BSD licensing isn't it? |
This comment has been minimized.
This comment has been minimized.
How about simply creating a fixed format |
NAG has a simple function called nagf_time_date_array_string that takes as input an If we can reach an agreement on the name and format I'm fine to have this. But in general the solution of @milancurcic will be more helpful. A downside of function nowstr()
character(len=:), allocatable :: nowstr
integer :: vals(8)
call date_and_time(values=vals)
! %c returns a date and time representation like:
! Sun Aug 19 02:56:02 2012
nowstr = fstrftime('%c',vals)
end function |
I would have use for stdlib provided derived type to express a time stamp since it would allow to bridge TOML Fortran and stdlib. This would allow to directly retrieve TOML documents as stdlib hash map including date time values from the TOML document as stdlib compatible derived type. |
A (simple) time stamp is already implemented in |
Description
For example, the Go language standard library has a time library golang/time, and
stdlib
also has a time module requirement. Is it possible to provide basic time module capabilities forstdlib
.Start
stdlib_time
module by implementing atime_stamp
function ?Prior Art
Fortran Time Packages
Related Issues
#1 and #106
The text was updated successfully, but these errors were encountered: