⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piece.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
    my $JD = $J + $G;    # Modify to include hours/mins/secs in floating portion.    return $JD + ($h + ($n + $s / 60) / 60) / 24;}sub week {    my $self = shift;    my $J  = $self->julian_day;    # Julian day is independent of time zone so add on tzoffset    # if we are using local time here since we want the week day    # to reflect the local time rather than UTC    $J += ($self->tzoffset/(24*3600)) if $self->[c_islocal];    # Now that we have the Julian day including fractions    # convert it to an integer Julian Day Number using nearest    # int (since the day changes at midday we oconvert all Julian    # dates to following midnight).    $J = int($J+0.5);    use integer;    my $d4 = ((($J + 31741 - ($J % 7)) % 146097) % 36524) % 1461;    my $L  = $d4 / 1460;    my $d1 = (($d4 - $L) % 365) + $L;    return $d1 / 7 + 1;}sub _is_leap_year {    my $year = shift;    return (($year %4 == 0) && !($year % 100 == 0)) || ($year % 400 == 0)               ? 1 : 0;}sub is_leap_year {    my $time = shift;    my $year = $time->year;    return _is_leap_year($year);}my @MON_LAST = qw(31 28 31 30 31 30 31 31 30 31 30 31);sub month_last_day {    my $time = shift;    my $year = $time->year;    my $_mon = $time->_mon;    return $MON_LAST[$_mon] + ($_mon == 1 ? _is_leap_year($year) : 0);}sub strftime {    my $time = shift;    my $tzname = $time->[c_islocal] ? '%Z' : 'UTC';    my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S $tzname";    if (!defined $time->[c_wday]) {        if ($time->[c_islocal]) {            return _strftime($format, CORE::localtime($time->epoch));        }        else {            return _strftime($format, CORE::gmtime($time->epoch));        }    }    return _strftime($format, (@$time)[c_sec..c_isdst]);}sub strptime {    my $time = shift;    my $string = shift;    my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S %Z";    my @vals = _strptime($string, $format);#    warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals)));    return scalar $time->_mktime(\@vals, (ref($time) ? $time->[c_islocal] : 0));}sub day_list {    shift if ref($_[0]) && $_[0]->isa(__PACKAGE__); # strip first if called as a method    my @old = @DAY_LIST;    if (@_) {        @DAY_LIST = @_;    }    return @old;}sub mon_list {    shift if ref($_[0]) && $_[0]->isa(__PACKAGE__); # strip first if called as a method    my @old = @MON_LIST;    if (@_) {        @MON_LIST = @_;    }    return @old;}sub time_separator {    shift if ref($_[0]) && $_[0]->isa(__PACKAGE__);    my $old = $TIME_SEP;    if (@_) {        $TIME_SEP = $_[0];    }    return $old;}sub date_separator {    shift if ref($_[0]) && $_[0]->isa(__PACKAGE__);    my $old = $DATE_SEP;    if (@_) {        $DATE_SEP = $_[0];    }    return $old;}use overload '""' => \&cdate,             'cmp' => \&str_compare,             'fallback' => undef;sub cdate {    my $time = shift;    if ($time->[c_islocal]) {        return scalar(CORE::localtime($time->epoch));    }    else {        return scalar(CORE::gmtime($time->epoch));    }}sub str_compare {    my ($lhs, $rhs, $reverse) = @_;    if (UNIVERSAL::isa($rhs, 'Time::Piece')) {        $rhs = "$rhs";    }    return $reverse ? $rhs cmp $lhs->cdate : $lhs->cdate cmp $rhs;}use overload        '-' => \&subtract,        '+' => \&add;sub subtract {    my $time = shift;    my $rhs = shift;    if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {        $rhs = $rhs->seconds;    }    if (shift)    {	# SWAPED is set (so someone tried an expression like NOTDATE - DATE).	# Imitate Perl's standard behavior and return the result as if the	# string $time resolves to was subtracted from NOTDATE.  This way,	# classes which override this one and which have a stringify function	# that resolves to something that looks more like a number don't need	# to override this function.	return $rhs - "$time";    }        if (UNIVERSAL::isa($rhs, 'Time::Piece')) {        return Time::Seconds->new($time->epoch - $rhs->epoch);    }    else {        # rhs is seconds.        return $time->_mktime(($time->epoch - $rhs), $time->[c_islocal]);    }}sub add {    my $time = shift;    my $rhs = shift;    if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {        $rhs = $rhs->seconds;    }    croak "Invalid rhs of addition: $rhs" if ref($rhs);    return $time->_mktime(($time->epoch + $rhs), $time->[c_islocal]);}use overload        '<=>' => \&compare;sub get_epochs {    my ($lhs, $rhs, $reverse) = @_;    if (!UNIVERSAL::isa($rhs, 'Time::Piece')) {        $rhs = $lhs->new($rhs);    }    if ($reverse) {        return $rhs->epoch, $lhs->epoch;    }    return $lhs->epoch, $rhs->epoch;}sub compare {    my ($lhs, $rhs) = get_epochs(@_);    return $lhs <=> $rhs;}1;__END__=head1 NAMETime::Piece - Object Oriented time objects=head1 SYNOPSIS    use Time::Piece;        my $t = localtime;    print "Time is $t\n";    print "Year is ", $t->year, "\n";=head1 DESCRIPTIONThis module replaces the standard localtime and gmtime functions withimplementations that return objects. It does so in a backwardscompatible manner, so that using localtime/gmtime in the way documentedin perlfunc will still return what you expect.The module actually implements most of an interface described byLarry Wall on the perl5-porters mailing list here:http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-01/msg00241.html=head1 USAGEAfter importing this module, when you use localtime or gmtime in a scalarcontext, rather than getting an ordinary scalar string representing thedate and time, you get a Time::Piece object, whose stringification happensto produce the same effect as the localtime and gmtime functions. There is also a new() constructor provided, which is the same as localtime(), exceptwhen passed a Time::Piece object, in which case it's a copy constructor. Thefollowing methods are available on the object:    $t->sec                 # also available as $t->second    $t->min                 # also available as $t->minute    $t->hour                # 24 hour    $t->mday                # also available as $t->day_of_month    $t->mon                 # 1 = January    $t->_mon                # 0 = January    $t->monname             # Feb    $t->month               # same as $t->monname    $t->fullmonth           # February    $t->year                # based at 0 (year 0 AD is, of course 1 BC)    $t->_year               # year minus 1900    $t->yy                  # 2 digit year    $t->wday                # 1 = Sunday    $t->_wday               # 0 = Sunday    $t->day_of_week         # 0 = Sunday    $t->wdayname            # Tue    $t->day                 # same as wdayname    $t->fullday             # Tuesday    $t->yday                # also available as $t->day_of_year, 0 = Jan 01    $t->isdst               # also available as $t->daylight_savings    $t->hms                 # 12:34:56    $t->hms(".")            # 12.34.56    $t->time                # same as $t->hms    $t->ymd                 # 2000-02-29    $t->date                # same as $t->ymd    $t->mdy                 # 02-29-2000    $t->mdy("/")            # 02/29/2000    $t->dmy                 # 29-02-2000    $t->dmy(".")            # 29.02.2000    $t->datetime            # 2000-02-29T12:34:56 (ISO 8601)    $t->cdate               # Tue Feb 29 12:34:56 2000    "$t"                    # same as $t->cdate    $t->epoch               # seconds since the epoch    $t->tzoffset            # timezone offset in a Time::Seconds object    $t->julian_day          # number of days since Julian period began    $t->mjd                 # modified Julian date (JD-2400000.5 days)    $t->week                # week number (ISO 8601)    $t->is_leap_year        # true if it its    $t->month_last_day      # 28-31    $t->time_separator($s)  # set the default separator (default ":")    $t->date_separator($s)  # set the default separator (default "-")    $t->day_list(@days)     # set the default weekdays    $t->mon_list(@days)     # set the default months    $t->strftime(FORMAT)    # same as POSIX::strftime (without the overhead                            # of the full POSIX extension)    $t->strftime()          # "Tue, 29 Feb 2000 12:34:56 GMT"        Time::Piece->strptime(STRING, FORMAT)                            # see strptime man page. Creates a new                            # Time::Piece object=head2 Local LocalesBoth wdayname (day) and monname (month) allow passing in a list to useto index the name of the days against. This can be useful if you needto implement some form of localisation without actually installing orusing locales.  my @days = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );  my $french_day = localtime->day(@days);These settings can be overriden globally too:  Time::Piece::day_list(@days);Or for months:  Time::Piece::mon_list(@months);And locally for months:  print localtime->month(@months);=head2 Date CalculationsIt's possible to use simple addition and subtraction of objects:    use Time::Seconds;        my $seconds = $t1 - $t2;    $t1 += ONE_DAY; # add 1 day (constant from Time::Seconds)The following are valid ($t1 and $t2 are Time::Piece objects):    $t1 - $t2; # returns Time::Seconds object    $t1 - 42; # returns Time::Piece object    $t1 + 533; # returns Time::Piece objectHowever adding a Time::Piece object to another Time::Piece objectwill cause a runtime error.Note that the first of the above returns a Time::Seconds object, sowhile examining the object will print the number of seconds (becauseof the overloading), you can also get the number of minutes, hours,days, weeks and years in that delta, using the Time::Seconds API.=head2 Date ComparisonsDate comparisons are also possible, using the full suite of "<", ">","<=", ">=", "<=>", "==" and "!=".=head2 Date ParsingTime::Piece links to your C library's strptime() function, allowingyou incredibly flexible date parsing routines. For example:  my $t = Time::Piece->strptime("Sun 3rd Nov, 1943",                                "%A %drd %b, %Y");    print $t->strftime("%a, %d %b %Y");Outputs:  Wed, 03 Nov 1943(see, it's even smart enough to fix my obvious date bug)For more information see "man strptime", which should be on all unixsystems.=head2 YYYY-MM-DDThh:mm:ssThe ISO 8601 standard defines the date format to be YYYY-MM-DD, andthe time format to be hh:mm:ss (24 hour clock), and if combined, theyshould be concatenated with date first and with a capital 'T' in frontof the time.=head2 Week NumberThe I<week number> may be an unknown concept to some readers.  The ISO8601 standard defines that weeks begin on a Monday and week 1 of theyear is the week that includes both January 4th and the first Thursdayof the year.  In other words, if the first Monday of January is the2nd, 3rd, or 4th, the preceding days of the January are part of thelast week of the preceding year.  Week numbers range from 1 to 53.=head2 Global OverridingFinally, it's possible to override localtime and gmtime everywhere, byincluding the ':override' tag in the import list:    use Time::Piece ':override';=head1 AUTHORMatt Sergeant, matt@sergeant.orgJarkko Hietaniemi, jhi@iki.fi (while creating Time::Piece for core perl)=head1 LicenseThis module is free software, you may distribute it under the same termsas Perl.=head1 SEE ALSOThe excellent Calendar FAQ at http://www.tondering.dk/claus/calendar.html=head1 BUGSThe test harness leaves much to be desired. Patches welcome.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -