| 1 | package SPVM::Sys::Time; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | SPVM::Sys::Time - System Calls for Time Manipulation | ||
| 8 | |||
| 9 | =head1 Description | ||
| 10 | |||
| 11 | Sys::Process class in L<SPVM> has methods to call system calls for time manipulation. | ||
| 12 | |||
| 13 | =head1 Usage | ||
| 14 | |||
| 15 | use Sys::Time; | ||
| 16 | |||
| 17 | my $epoch = Sys::Time->time; | ||
| 18 | |||
| 19 | my $time_info_local = Sys::Time->localtime($epoch); | ||
| 20 | |||
| 21 | my $time_info_utc = Sys::Time->gmtime($epoch); | ||
| 22 | |||
| 23 | =head1 Class Methods | ||
| 24 | |||
| 25 | =head2 time | ||
| 26 | |||
| 27 | C<static method time : long ();> | ||
| 28 | |||
| 29 | Calls L<time|https://linux.die.net/man/2/time> function and returns its return value. | ||
| 30 | |||
| 31 | =head2 localtime | ||
| 32 | |||
| 33 | C<static method localtime : L<Sys::Time::Tm|SPVM::Sys::Time::Tm> ($time_ref : long*);> | ||
| 34 | |||
| 35 | Calls L<localtime|https://linux.die.net/man/3/localtime> function and creates a L<Sys::Time::Tm|SPVM::Sys::Time::Tm> object given its return value, and returns it. | ||
| 36 | |||
| 37 | Exceptions: | ||
| 38 | |||
| 39 | The reference of the time $time must be defined. Otherwise an exception is thrown. | ||
| 40 | |||
| 41 | =head2 gmtime | ||
| 42 | |||
| 43 | C<static method gmtime : L<Sys::Time::Tm|SPVM::Sys::Time::Tm> ($time_ref : long*);> | ||
| 44 | |||
| 45 | Calls L<gmtime|https://linux.die.net/man/3/gmtime> function and creates a L<Sys::Time::Tm|SPVM::Sys::Time::Tm> object given its return value, and returns it. | ||
| 46 | |||
| 47 | Exceptions: | ||
| 48 | |||
| 49 | The reference of the time $time must be defined. Otherwise an exception is thrown. | ||
| 50 | |||
| 51 | =head2 gettimeofday | ||
| 52 | |||
| 53 | C<static method gettimeofday : int ($tv : L<Sys::Time::Timeval|SPVM::Sys::Time::Timeval>, $tz : object = undef);> | ||
| 54 | |||
| 55 | Calls L<gmtime|https://linux.die.net/man/2/gettimeofday> function and creates a L<Sys::Time::Timeval|SPVM::Sys::Time::Timeval> object given its return value, and returns it. | ||
| 56 | |||
| 57 | Exceptions: | ||
| 58 | |||
| 59 | If the gettimeofday function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 60 | |||
| 61 | Timezone $tz is not supported. | ||
| 62 | |||
| 63 | =head2 clock | ||
| 64 | |||
| 65 | C<static method clock : long ()> | ||
| 66 | |||
| 67 | Calls L<clock|https://linux.die.net/man/3/clock> function, and returns its return value. | ||
| 68 | |||
| 69 | Exceptions: | ||
| 70 | |||
| 71 | If the clock function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 72 | |||
| 73 | =head2 clock_gettime | ||
| 74 | |||
| 75 | C<static method clock_gettime : int ($clk_id : int, $tp : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>);> | ||
| 76 | |||
| 77 | Calls L<clock_gettime|https://linux.die.net/man/3/clock_gettime> function, and returns its return value. | ||
| 78 | |||
| 79 | See L<Sys::Time::Constant|SPVM::Sys::Time::Constant> about constant values given to $clk_id. | ||
| 80 | |||
| 81 | Exceptions: | ||
| 82 | |||
| 83 | $tp must be defined. Otherwise an exception is thrown. | ||
| 84 | |||
| 85 | If the clock_gettime function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 86 | |||
| 87 | =head2 clock_getres | ||
| 88 | |||
| 89 | C<static method clock_getres : int ($clk_id : int, $res : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>);> | ||
| 90 | |||
| 91 | Calls L<clock_getres|https://linux.die.net/man/3/clock_getres> function, and returns its return value. | ||
| 92 | |||
| 93 | See L<Sys::Time::Constant|SPVM::Sys::Time::Constant> about constant values given to $clk_id. | ||
| 94 | |||
| 95 | Exceptions: | ||
| 96 | |||
| 97 | $res must be defined. Otherwise an exception is thrown. | ||
| 98 | |||
| 99 | If the clock_getres function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 100 | |||
| 101 | =head2 setitimer | ||
| 102 | |||
| 103 | C<static method setitimer : int ($which : int, $new_value : L<Sys::Time::Itimerval|SPVM::Sys::Time::Itimerval>, $old_value : L<Sys::Time::Itimerval|SPVM::Sys::Time::Itimerval>)> | ||
| 104 | |||
| 105 | Calls L<setitimer|https://linux.die.net/man/2/setitimer> function, and returns its return value. | ||
| 106 | |||
| 107 | See L<Sys::Time::Constant|SPVM::Sys::Time::Constant> about constant values given to $which. | ||
| 108 | |||
| 109 | Exceptions: | ||
| 110 | |||
| 111 | $new_value must be defined. Otherwise an exception is thrown. | ||
| 112 | |||
| 113 | If the clock_getres function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 114 | |||
| 115 | In Windows the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. setitimer is not supported in this system(defined(_WIN32)). | ||
| 116 | |||
| 117 | =head2 getitimer | ||
| 118 | |||
| 119 | C<static method getitimer : int ($which : int, $curr_value : L<Sys::Time::Itimerval|SPVM::Sys::Time::Itimerval>);> | ||
| 120 | |||
| 121 | Calls L<getitimer|https://linux.die.net/man/2/getitimer> function, and returns its return value. | ||
| 122 | |||
| 123 | See L<Sys::Time::Constant|SPVM::Sys::Time::Constant> about constant values given to $which. | ||
| 124 | |||
| 125 | Exceptions: | ||
| 126 | |||
| 127 | $curr_value must be defined. Otherwise an exception is thrown. | ||
| 128 | |||
| 129 | If the getitimer function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 130 | |||
| 131 | In Windows the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. getitimer is not supported in this system(defined(_WIN32)). | ||
| 132 | |||
| 133 | =head2 times | ||
| 134 | |||
| 135 | C<static method times : long ($buffer : L<Sys::Time::Tms|SPVM::Sys::Time::Tms>);> | ||
| 136 | |||
| 137 | Calls L<times|https://linux.die.net/man/2/times> function, and returns its return value. | ||
| 138 | |||
| 139 | Exceptions: | ||
| 140 | |||
| 141 | $tms must be defined. Otherwise an exception is thrown. | ||
| 142 | |||
| 143 | If the times function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 144 | |||
| 145 | In Windows the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. times is not supported in this system(defined(_WIN32)). | ||
| 146 | |||
| 147 | =head2 clock_nanosleep | ||
| 148 | |||
| 149 | C<static method clock_nanosleep : int ($clockid : int, $flags : int, $request : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>, $remain : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>);> | ||
| 150 | |||
| 151 | Calls L<clock_nanosleep|https://linux.die.net/man/2/clock_nanosleep> function, and returns its return value. | ||
| 152 | |||
| 153 | See L<Sys::Time::Constant|SPVM::Sys::Time::Constant> about constant values given to $clockid and $flags. | ||
| 154 | |||
| 155 | Exceptions: | ||
| 156 | |||
| 157 | $request must be defined. Otherwise an exception is thrown. | ||
| 158 | |||
| 159 | In Mac the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. clock_nanosleep is not supported in this system(__APPLE__). | ||
| 160 | |||
| 161 | =head2 nanosleep | ||
| 162 | |||
| 163 | C<static method nanosleep : int ($rqtp : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>, $rmtp : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec>);> | ||
| 164 | |||
| 165 | Calls L<nanosleep|https://linux.die.net/man/3/nanosleep> function, and returns its return value. | ||
| 166 | |||
| 167 | Exceptions: | ||
| 168 | |||
| 169 | $rqtp must be defined. Otherwise an exception is thrown. | ||
| 170 | |||
| 171 | If the nanosleep function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::System|SPVM::Error::System>. | ||
| 172 | |||
| 173 | =head2 utime | ||
| 174 | |||
| 175 | C<static method utime : int ($filename : string, $times : L<Sys::Time::Utimbuf|SPVM::Sys::Time::Utimbuf>);> | ||
| 176 | |||
| 177 | Calls L<utime|https://linux.die.net/man/2/utime> function, and returns its return value. | ||
| 178 | |||
| 179 | =head2 utimes | ||
| 180 | |||
| 181 | C<static method utimes : int ($filename : string, $times : L<Sys::Time::Timeval|SPVM::Sys::Time::Timeval>[]);> | ||
| 182 | |||
| 183 | Calls L<utimes|https://linux.die.net/man/2/utimes> function, and returns its return value. | ||
| 184 | |||
| 185 | The utime() system call changes the access and modification times of the inode specified by filename to the actime and modtime fields of times respectively. | ||
| 186 | |||
| 187 | =head2 tzset | ||
| 188 | |||
| 189 | C<static method tzset : void ();> | ||
| 190 | |||
| 191 | Initializes time conversion information from the environment variable B<TZ>. | ||
| 192 | |||
| 193 | See L<tzset|https://pubs.opengroup.org/onlinepubs/9699919799/functions/tzset.html> function in the POSIX branch of the Single UNIX Specification. | ||
| 194 | |||
| 195 | =head1 See Also | ||
| 196 | |||
| 197 | =over 2 | ||
| 198 | |||
| 199 | =item * L<Sys|SPVM::Sys> | ||
| 200 | |||
| 201 | =back | ||
| 202 | |||
| 203 | =head1 Copyright & License | ||
| 204 | |||
| 205 | Copyright (c) 2023 Yuki Kimoto | ||
| 206 | |||
| 207 | MIT License | ||
| 208 |