Skip to content
API Documentation
BastionGuard™
TeeJee.Misc Namespace Reference

Functions

void set_numeric_locale (string type)
string timestamp (bool show_millis=false)
string timestamp_numeric ()
string timestamp_for_path ()
string format_duration (double millis)
string escape_html (string html)
string random_string (int length=8, string charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")

Function Documentation

◆ escape_html()

◆ format_duration()

string TeeJee.Misc.format_duration ( double millis)

Definition at line 78 of file TeeJee.Misc.vala.

78 {
79
80 /* Converts time in milliseconds to format '00:00:00.0' */
81
82 double time = millis / 1000.0; // time in seconds
83
84 double hr = Math.floor(time / (60.0 * 60));
85 time = time - (hr * 60 * 60);
86 double min = Math.floor(time / 60.0);
87 time = time - (min * 60);
88 double sec = Math.floor(time);
89
90 return "%02.0lf:%02.0lf:%02.0lf".printf (hr, min, sec);
91 }

References format_duration().

Referenced by format_duration().

◆ random_string()

string TeeJee.Misc.random_string ( int length = 8,
string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" )

Definition at line 98 of file TeeJee.Misc.vala.

98 {
99
100 string random = "";
101
102 for(int i=0;i<length;i++){
103 int random_index = Random.int_range(0,charset.length);
104 string ch = charset.get_char(charset.index_of_nth_char(random_index)).to_string();
105 random += ch;
106 }
107
108 return random;
109 }

References random_string().

Referenced by DeleteFileTask.build_script(), TeeJee.ProcessHelper.init_tmp(), and random_string().

◆ set_numeric_locale()

void TeeJee.Misc.set_numeric_locale ( string type)

Definition at line 36 of file TeeJee.Misc.vala.

36 {
37 Intl.setlocale(GLib.LocaleCategory.NUMERIC, type);
38 Intl.setlocale(GLib.LocaleCategory.COLLATE, type);
39 Intl.setlocale(GLib.LocaleCategory.TIME, type);
40 }

References set_numeric_locale().

Referenced by set_numeric_locale(), and TeeJee.System.set_numeric_locale().

◆ timestamp()

string TeeJee.Misc.timestamp ( bool show_millis = false)

Definition at line 44 of file TeeJee.Misc.vala.

44 {
45
46 /* Returns a formatted timestamp string */
47
48 // NOTE: format() does not support milliseconds
49
50 DateTime now = new GLib.DateTime.now_local();
51
52 if (show_millis){
53 var msec = now.get_microsecond () / 1000;
54 return "%s.%03d".printf(now.format("%H:%M:%S"), msec);
55 }
56 else{
57 return now.format ("%H:%M:%S");
58 }
59 }

References timestamp().

Referenced by TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), TeeJee.Logging.log_to_file(), and timestamp().

◆ timestamp_for_path()

string TeeJee.Misc.timestamp_for_path ( )

Definition at line 68 of file TeeJee.Misc.vala.

68 {
69
70 /* Returns a formatted timestamp string */
71
72 Time t = Time.local (time_t ());
73 return t.format ("%Y-%m-%d_%H-%M-%S");
74 }

References timestamp_for_path().

Referenced by AsyncTask.AsyncTask(), and timestamp_for_path().

◆ timestamp_numeric()

string TeeJee.Misc.timestamp_numeric ( )

Definition at line 61 of file TeeJee.Misc.vala.

61 {
62
63 /* Returns a numeric timestamp string */
64
65 return "%ld".printf((long) time_t ());
66 }

References timestamp_numeric().

Referenced by TeeJee.ProcessHelper.get_temp_file_path(), and timestamp_numeric().