source: to-imperative/trunk/library/Dos/time.cc @ 1086

Last change on this file since 1086 was 1086, checked in by luba, 17 years ago
  • 0 is added to milliseconds if the number is < 10;
  • date and time were changed to terms of type_short_int
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
1// $Source$
2// $Revision: 1086 $
3// $Date: 2003-08-02 10:39:06 +0000 (Sat, 02 Aug 2003) $
4// $Author: luba $
5
6#include <rf_core.hh>
7#include <stdlib.h>
8#include <time.h>
9#include <sys/time.h>
10#include <locale.h>
11
12namespace refal
13{
14using namespace rfrt;
15using namespace rftype;
16
17namespace Dos
18{
19
20RF_FUNC (Time, (), (RF_RES e_String))
21 
22  struct timeval ttt;
23  struct tm* lt; 
24  unsigned uu;
25
26  setlocale(LC_TIME, "");
27
28  gettimeofday(&ttt,NULL); 
29  lt = localtime (&(ttt.tv_sec)); 
30  uu = ttt.tv_usec/10000; 
31
32  char s[256]; 
33
34  strftime(s, sizeof(s), " %b ", lt);
35
36  Expr e = ShortInt::create_expr((*lt).tm_mday) +
37           Word::create_expr(s) +
38           ShortInt::create_expr((*lt).tm_year + 1900) +
39           Char::create_expr(" ") +
40           ShortInt::create_expr((*lt).tm_hour) +
41           Char::create_expr(":") +
42           ShortInt::create_expr((*lt).tm_min) +
43           Char::create_expr(":") +
44           ShortInt::create_expr((*lt).tm_sec) +
45           Char::create_expr(".");
46
47  if (uu < 10) 
48    e = e + ShortInt::create_expr(0) +
49            ShortInt::create_expr(uu);
50  else 
51    e = e + ShortInt::create_expr(uu);
52
53  e_String = e;
54
55RF_END
56}
57}
58
59
Note: See TracBrowser for help on using the repository browser.