Time::Clock(3pm)
๐ NAME ๐
Time::Clock โ a twenty-four hour clock object with nanosecond precision.
yk what that means bestie? it's a clock. just a clock. no dates, no vibes about what day it is, just time. and it's precise down to the nanosecond, which is genuinely iconic of it. ๐ฐ๏ธโจ
(this is the Time::Clock page from the User Contributed Perl Documentation manual, in case you were wondering where you wandered into ๐)
๐ธ SYNOPSIS ๐ธ
$t = Time::Clock->new(hour => 12, minute => 34, second => 56);
print $t->as_string; # 12:34:56
$t->parse('8pm');
print "$t"; # 20:00:00
print $t->format('%I:%M %p'); # 08:00 PM
$t->add(minutes => 15, nanoseconds => 123000000);
print $t->as_string; # 20:15:00.123
$t->subtract(hours => 30);
print $t->as_string; # 14:15:00.123
...
look at her go ๐ญ she's just doing that. no cap.
๐ฆ DESCRIPTION ๐ฆ
A Time::Clock object is a twenty-four hour clock with nanosecond precision and wrap-around. It is a clock only โ it has absolutely no concept of dates. Not even a little. Vagaries of date/time such as leap seconds and daylight savings time are unsupported. she simply does not know about them and she is not going to learn. ๐
When a Time::Clock object hits 23:59:59.999999999 and at least one more nanosecond is added, it will wrap around to 00:00:00.000000000. This works in reverse when time is subtracted. circling around like a lil ouroboros ๐โจ
Time::Clock objects automatically stringify to a user-definable format. main character energy fr.
๐ CLASS METHODS ๐
๐ซ default_format FORMAT
Set the default format used by the as_string method for all objects of this class. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers.
Note that this method may also be called as an object method, in which case it sets the default format for the individual object only. so like, choose your scope, bestie ๐
๐ CONSTRUCTOR ๐
new PARAMS
Constructs a new Time::Clock object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name. Example:
$t = Time::Clock->new(hour => 12, minute => 34, second => 56);
If a single argument is passed to new, it is equivalent to calling the parse method. That is, this:
$t = Time::Clock->new('12:34:56');
is equivalent to this:
$t = Time::Clock->new;
$t->parse('12:34:56');
Returns the newly constructed Time::Clock object. new baby just dropped ๐ผ๐
๐ OBJECT METHODS ๐
add PARAMS
Add the time specified by PARAMS to the clock. Valid PARAMS are:
"hours INT"โ An integer number of hours."minutes INT"โ An integer number of minutes."seconds INT"โ An integer number of seconds."nanoseconds INT"โ An integer number of nanoseconds.
If the amount of time added is large enough, the clock will wrap around from 23:59:59.999999999 to 00:00:00.000000000 as needed. bye bye today's hours, hello tomorrow's ๐โจ
ampm AM/PM
Get or set the AM/PM attribute of the clock. Valid values of AM/PM must contain the letters "AM" or "PM" (case-insensitive), optionally followed by periods.
A clock whose hour is greater than 12 cannot be set to AM. Any attempt to do so will cause a fatal error. ๐ so don't.
Setting a clock whose hour is less than 12 to PM will cause its hour to be increased by 12. Example:
$t = Time::Clock->new('8:00');
print $t->as_string; # 08:00:00
$t->ampm('PM');
print $t->as_string; # 20:00:00
Return the string "AM" if the hour is less than 12, "PM" otherwise.
as_integer_seconds
Returns the integer number of seconds since 00:00:00. raw, unfiltered, no frills ๐งฎ
as_string
Returns a string representation of the clock, formatted according to the clock object's default_format. the strings are stringing โจ
default_format FORMAT
Set the default format used by the as_string method for this object. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers.
Note that this method may also be called as a class method, in which case it sets the default format all objects of this class. (yes bestie, she swings both ways โ object and class ๐ซถ)
format FORMAT
Returns the clock value formatted according to the FORMAT string containing "%"-prefixed format specifiers. Valid format specifiers are:
%Hโ The hour as a two-digit, zero-padded integer using a 24-hour clock (range00to23).%Iโ The hour as a two-digit, zero-padded integer using a 12-hour clock (range01to12).%iโ The hour as an integer using a 12-hour clock (range1to12).%kโ The hour as an integer using a 24-hour clock (range0to23).%Mโ The minute as a two-digit, zero-padded integer (range00to59).%nโ If the clock has a non-zero nanosecond value, then this format produces a decimal point followed by the fractional seconds up to and including the last non-zero digit. If no nanosecond value is defined, or if it is zero, then this format produces an empty string. Examples:
$t = Time::Clock->new('12:34:56');
print $t->format('%H:%M:%S%n'); # 12:34:56
$t->nanosecond(0);
print $t->format('%H:%M:%S%n'); # 12:34:56
$t->nanosecond(123000000);
print $t->format('%H:%M:%S%n'); # 12:34:56.123
"%[1-9]n"โ If the clock has a defined nanosecond value, then this format produces a decimal point followed by the specified number of digits of fractional seconds (1-9). Examples:
$t = Time::Clock->new('12:34:56');
print $t->format('%H:%M:%S%4n'); # 12:34:56
$t->nanosecond(0);
print $t->format('%H:%M:%S%4n'); # 12:34:56.0000
$t->nanosecond(123000000);
print $t->format('%H:%M:%S%4n'); # 12:34:56.1230
%Nโ Nanoseconds as a nine-digit, zero-padded integer (range000000000to999999999)"%[1-9]N"โ Fractional seconds as a one- to nine-digit, zero-padded integer. Examples:
$t = Time::Clock->new('12:34:56');
print $t->format('%H:%M:%S.%4N'); # 12:34:56.0000
$t->nanosecond(123000000);
print $t->format('%H:%M:%S.%6N'); # 12:34:56.123000
$t->nanosecond(123000000);
print $t->format('%H:%M:%S.%2N'); # 12:34:56.12
%pโ Either"AM"or"PM"according to the value return by theampmmethod.%Pโ Like%pbut lowercase:"am"or"pm"%Sโ The second as a two-digit, zero-padded integer (range00to61).%sโ The integer number of seconds since00:00:00.%Tโ The time in 24-hour notation (%H:%M:%S)."%%"โ A literal"%"character.
that's a LOT of specifiers and every single one of them ate ๐ฅ no skipping, we're thorough in this household.
hour INT
Get or set the hour of the clock. INT must be an integer from 0 to 23.
minute INT
Get or set the minute of the clock. INT must be an integer from 0 to 59.
nanosecond INT
Get or set the nanosecond of the clock. INT must be an integer from 0 to 999999999. one billionth of a second, obsessed with her precision ๐ญโฑ๏ธ
parse STRING
Set the clock time by parsing STRING. The invoking object is returned.
Valid string values contain an hour with optional minutes, seconds, fractional seconds, and AM/PM string. There should be a colon (":") between hours, minutes, and seconds, and a decimal point (".") between the seconds and fractional seconds. Fractional seconds may contain up to 9 digits. The AM/PM string is case-insensitive and may have periods after each letter.
The string "now" will initialize the clock object with the current (local) time. If the Time::HiRes module is installed, this time will have fractional seconds. โจ
A time value with an hour of 24 and zero minutes, seconds, and nanoseconds is also accepted by this method.
Here are some examples of valid time strings:
12:34:56.123456789
12:34:56.123 PM
24:00
8:30pm
6 A.m.
now
yes you can just say now and she gets it, she's flexible like that ๐ง
second INT
Get or set the second of the clock. INT must be an integer from 0 to 59.
subtract PARAMS
Subtract the time specified by PARAMS from the clock. Valid PARAMS are:
"hours INT"โ An integer number of hours."minutes INT"โ An integer number of minutes."seconds INT"โ An integer number of seconds."nanoseconds INT"โ An integer number of nanoseconds.
If the amount of time subtracted is large enough, the clock will wrap around from 00:00:00.000000000 to 23:59:59.999999999 as needed. going backwards but make it dramatic ๐ซ
๐ AUTHOR ๐
John C. Siracusa (siracusa@gmail.com)
legend behavior honestly ๐
๐ LICENSE ๐
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay bestie that's the whole page, you read it, you understood it, you're basically a clock engineer now ๐ and for the record โ this was perl v5.36.0, dated 2022-10-22, and it lives in the Time::Clock(3pm) section. go forth and format timestamps ๐๐ฆโจ
๐ฆ where this page comes from
- ubuntu noble: libtime-clock-perl 1.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtime-clock-perl 1.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtime-clock-perl 1.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms