File: DateAndTime.cxx

package info (click to toggle)
caret 5.6.4~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 31,904 kB
  • ctags: 28,901
  • sloc: cpp: 378,050; python: 6,718; ansic: 5,507; makefile: 333; sh: 46
file content (66 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* 
 * File:   dateandtime.cxx
 * Author: john
 * 
 * Created on June 23, 2009, 11:49 AM
 */

#include "DateAndTime.h"

#include <QChar>
#include <QDateTime>

/**
 * Get the current date and time in a string.  This methods returns
 * a format that should not crash like the locale date format does if
 * written to a text file.
 *
 * Returned date is in form:
 *   23 Jun 2009 11:57:13
 */
QString 
DateAndTime::getDateAndTimeAsString()
{
   QString s = QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate);
   return s;
}

/**
 * Get the current date and time in a string.  This methods returns
 * a format that should not crash like the locale date format does if
 * written to a text file.
 *
 * Returned date is in form:
 *   23_Jun_2009_11_57_13
 */
QString
DateAndTime::getDateAndTimeForNaming()
{
   QString s = QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate);

   for (int i = 0; i < s.length(); i++) {
      if (s.at(i).isLetterOrNumber() == false) {
         s[i] = '_';
      }
   }
   
   return s;
}

/**
 * get the date in a string for naming.
 */
QString
DateAndTime::getDateForNaming()
{
   QString s = QDate::currentDate().toString(Qt::DefaultLocaleShortDate);

   for (int i = 0; i < s.length(); i++) {
      if (s.at(i).isLetterOrNumber() == false) {
         s[i] = '_';
      }
   }

   return s;
}