line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
109647
|
use strict; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
51
|
|
2
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
3
|
|
|
|
|
|
|
package Time::Piece::MSSQL 0.023; |
4
|
2
|
|
|
2
|
|
861
|
use Time::Piece 1.17; |
|
2
|
|
|
|
|
20189
|
|
|
2
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: MSSQL-specific methods for Time::Piece |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# stolen from timepiece-mysql |
8
|
|
|
|
|
|
|
sub import { |
9
|
2
|
|
|
2
|
|
19
|
splice @_, 0, 1, 'Time::Piece'; |
10
|
2
|
|
|
|
|
10
|
goto &Time::Piece::import |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
14
|
|
|
|
|
|
|
#pod |
15
|
|
|
|
|
|
|
#pod use Time::Piece::MSSQL; |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod my $time = localtime; |
18
|
|
|
|
|
|
|
#pod |
19
|
|
|
|
|
|
|
#pod print $time->mssql_datetime; |
20
|
|
|
|
|
|
|
#pod print $time->mssql_smalldatetime; |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod my $time = Time::Piece->from_mssql_datetime( $mssql_datetime ); |
23
|
|
|
|
|
|
|
#pod my $time = Time::Piece->from_mssql_smalldatetime( $mssql_smalldatetime ); |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod This module adds functionality to L, providing methods useful for |
28
|
|
|
|
|
|
|
#pod using the object in conjunction with a Microsoft SQL database connection. It |
29
|
|
|
|
|
|
|
#pod will produce and parse MSSQL's default-format datetime values. |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod =method mssql_datetime |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod =method mssql_smalldatetime |
34
|
|
|
|
|
|
|
#pod |
35
|
|
|
|
|
|
|
#pod These methods return the Time::Piece object, formatted in the default notation |
36
|
|
|
|
|
|
|
#pod for the correct MSSQL datatype. |
37
|
|
|
|
|
|
|
#pod |
38
|
|
|
|
|
|
|
#pod =cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub mssql_datetime { |
41
|
1
|
|
|
1
|
1
|
664
|
my $self = shift; |
42
|
1
|
|
|
|
|
5
|
$self->strftime('%Y-%m-%d %H:%M:%S.000'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub mssql_smalldatetime { |
46
|
1
|
|
|
1
|
1
|
925
|
my $self = shift; |
47
|
1
|
|
|
|
|
5
|
$self->strftime('%Y-%m-%d %H:%M:%S'); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#pod =method from_mssql_datetime |
51
|
|
|
|
|
|
|
#pod |
52
|
|
|
|
|
|
|
#pod my $time = Time::Piece->from_mssql_datetime($timestring); |
53
|
|
|
|
|
|
|
#pod |
54
|
|
|
|
|
|
|
#pod =method from_mssql_smalldatetime |
55
|
|
|
|
|
|
|
#pod |
56
|
|
|
|
|
|
|
#pod my $time = Time::Piece->from_mssql_smalldatetime($timestring); |
57
|
|
|
|
|
|
|
#pod |
58
|
|
|
|
|
|
|
#pod These methods construct new Time::Piece objects from the given strings, which |
59
|
|
|
|
|
|
|
#pod must be in the default MSSQL format for the correct datatype. If the string is |
60
|
|
|
|
|
|
|
#pod empty, undefined, or unparseable, C is returned. |
61
|
|
|
|
|
|
|
#pod |
62
|
|
|
|
|
|
|
#pod =cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub from_mssql_datetime { |
65
|
6
|
|
|
6
|
1
|
8932
|
my ($class, $timestring) = @_; |
66
|
6
|
100
|
100
|
|
|
41
|
return unless $timestring and ($timestring =~ s/\.\d{3}$//); |
67
|
4
|
|
|
|
|
7
|
my $time = eval { $class->strptime($timestring, '%Y-%m-%d %H:%M:%S') }; |
|
4
|
|
|
|
|
11
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub from_mssql_smalldatetime { |
71
|
6
|
|
|
6
|
1
|
11394
|
my ($class, $timestring) = @_; |
72
|
6
|
100
|
|
|
|
17
|
return unless $timestring; |
73
|
5
|
|
|
|
|
7
|
my $time = eval { $class->strptime($timestring, '%Y-%m-%d %H:%M:%S') }; |
|
5
|
|
|
|
|
13
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
BEGIN { |
77
|
2
|
|
|
2
|
|
8
|
for (qw( |
78
|
|
|
|
|
|
|
mssql_datetime mssql_smalldatetime |
79
|
|
|
|
|
|
|
from_mssql_datetime from_mssql_smalldatetime |
80
|
|
|
|
|
|
|
)) { |
81
|
2
|
|
|
2
|
|
464
|
no strict 'refs'; ## no critic ProhibitNoStrict |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
82
|
8
|
|
|
|
|
32
|
*{"Time::Piece::$_"} = __PACKAGE__->can($_); |
|
8
|
|
|
|
|
77
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#pod =head1 FINAL THOUGHTS |
87
|
|
|
|
|
|
|
#pod |
88
|
|
|
|
|
|
|
#pod This module saves less time than L, because there are fewer |
89
|
|
|
|
|
|
|
#pod strange quirks to account for, but it becomes useful when tied to autoinflation |
90
|
|
|
|
|
|
|
#pod of datatypes in Class::DBI::MSSQL. |
91
|
|
|
|
|
|
|
#pod |
92
|
|
|
|
|
|
|
#pod =cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |