| 1 | package DBIO::MSSQL::Storage::DateTime::Format; | ||
| 2 | # ABSTRACT: DateTime parser for MSSQL datetime and smalldatetime columns | ||
| 3 | |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 2 | ▶ | use base 'DBIO::Storage::DateTimeFormat'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | # MSSQL adds a third channel beyond the base datetime/date: smalldatetime | ||
| 10 | # (minute precision, no fractional seconds). Core's InflateColumn::DateTime | ||
| 11 | # routes it to parse_smalldatetime/format_smalldatetime when the parser | ||
| 12 | # ->can() them, otherwise falls back to parse_datetime/format_datetime. | ||
| 13 | 2 | __PACKAGE__->mk_group_accessors('inherited' => qw/ | |
| 14 | smalldatetime_parse_pattern smalldatetime_format_pattern | ||
| 15 | /); | ||
| 16 | |||
| 17 | 2 | __PACKAGE__->datetime_parse_pattern('%Y-%m-%d %H:%M:%S.%3N'); # %F %T | |
| 18 | 2 | __PACKAGE__->datetime_format_pattern('%Y-%m-%d %H:%M:%S.%3N'); | |
| 19 | 2 | __PACKAGE__->smalldatetime_parse_pattern('%Y-%m-%d %H:%M:%S'); | |
| 20 | 2 | __PACKAGE__->smalldatetime_format_pattern('%Y-%m-%d %H:%M:%S'); | |
| 21 | |||
| 22 | |||
| 23 | 1 | ▶ | sub parse_smalldatetime { |
|
Subroutine
parse_smalldatetime: called CC=1 SCAR=0.0
Pod
documented
| |||
| 24 | 1 | my ($class, $value) = @_; | |
| 25 | |||
| 26 | 1 | return $class->_strptime_for(smalldatetime_parse => 'smalldatetime_parse_pattern') | |
| 27 | ->parse_datetime($value); | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | 1 | ▶ | sub format_smalldatetime { |
|
Subroutine
format_smalldatetime: called CC=1 SCAR=0.0
Pod
documented
| |||
| 32 | 1 | my ($class, $dt) = @_; | |
| 33 | |||
| 34 | 1 | return $class->_strptime_for(smalldatetime_format => 'smalldatetime_format_pattern') | |
| 35 | ->format_datetime($dt); | ||
| 36 | } | ||
| 37 | |||
| 38 | 2 | 1; | |
| 39 | |||
| 40 | __END__ | ||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =encoding UTF-8 | ||
| 45 | |||
| 46 | =head1 NAME | ||
| 47 | |||
| 48 | DBIO::MSSQL::Storage::DateTime::Format - DateTime parser for MSSQL datetime and smalldatetime columns | ||
| 49 | |||
| 50 | =head1 VERSION | ||
| 51 | |||
| 52 | version 0.900001 | ||
| 53 | |||
| 54 | =head1 METHODS | ||
| 55 | |||
| 56 | =head2 parse_smalldatetime | ||
| 57 | |||
| 58 | my $dt = $class->parse_smalldatetime($string); | ||
| 59 | |||
| 60 | Parses a C<smalldatetime> string (minute precision) into a L<DateTime>. | ||
| 61 | |||
| 62 | =head2 format_smalldatetime | ||
| 63 | |||
| 64 | my $string = $class->format_smalldatetime($dt); | ||
| 65 | |||
| 66 | Formats a L<DateTime> for a C<smalldatetime> column. | ||
| 67 | |||
| 68 | =head1 AUTHOR | ||
| 69 | |||
| 70 | DBIO & DBIx::Class Authors | ||
| 71 | |||
| 72 | =head1 COPYRIGHT AND LICENSE | ||
| 73 | |||
| 74 | Copyright (C) 2026 DBIO Authors | ||
| 75 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||
| 76 | Based on DBIx::Class, heavily modified. | ||
| 77 | |||
| 78 | This is free software; you can redistribute it and/or modify it under | ||
| 79 | the same terms as the Perl 5 programming language system itself. | ||
| 80 | |||
| 81 | =cut | ||