| 1 | package DBIO::MSSQL::Storage::Sybase::DateTime::Format; | ||||||||||
| 2 | # ABSTRACT: DateTime parser for MSSQL via DBD::Sybase | ||||||||||
| 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 | our $VERSION = '0.900007'; | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use base 'DBIO::Storage::DateTimeFormat'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # Asymmetric: DBD::Sybase with syb_date_fmt('ISO_strict') emits ISO on read, | ||||||||||
| 12 | # but MSSQL wants a plain datetime literal on write, in the form YYYYMMDD | ||||||||||
| 13 | # (no dashes): the dashed form is read by the DATEFORMAT of the session. No preferred_format_class: | ||||||||||
| 14 | # DateTime::Format::MSSQL is mdy-based and does not round-trip with ISO_strict. | ||||||||||
| 15 | 2 | __PACKAGE__->datetime_parse_pattern('%Y-%m-%dT%H:%M:%S.%3NZ'); | |||||||||
| 16 | 2 | __PACKAGE__->datetime_format_pattern('%Y%m%d %H:%M:%S.%3N'); | |||||||||
| 17 | # A date column comes back through the same ISO_strict conversion, as a | ||||||||||
| 18 | # datetime at midnight (2026-10-25T00:00:00.000Z); written as YYYYMMDD. | ||||||||||
| 19 | 2 | __PACKAGE__->date_parse_pattern('%Y-%m-%dT%H:%M:%S.%3NZ'); | |||||||||
| 20 | 2 | __PACKAGE__->date_format_pattern('%Y%m%d'); | |||||||||
| 21 | |||||||||||
| 22 | # datetime2, datetimeoffset and time: what DBD::Sybase hands over depends on the | ||||||||||
| 23 | # TDS version FreeTDS speaks (measured, MSSQL 2022, FreeTDS 1.3.17): | ||||||||||
| 24 | # TDS 7.0 - 7.2 the server sends the new types as text, in full: | ||||||||||
| 25 | # '2026-10-25 13:14:15.1234567', | ||||||||||
| 26 | # '2026-10-05 13:14:15.1234567 +02:00', '13:14:15.1234567' | ||||||||||
| 27 | # TDS 7.3, 7.4 the client library converts them to its datetime and | ||||||||||
| 28 | # syb_date_fmt('ISO_strict') writes that: milliseconds only, | ||||||||||
| 29 | # a datetimeoffset as the UTC instant ('2026-10-05T11:14:15.123Z', | ||||||||||
| 30 | # the offset is gone), a time with a day that is not the time's | ||||||||||
| 31 | # ('2026-10-05T13:14:15.123Z') | ||||||||||
| 32 | # The parsers take both; the second form loses what the client library dropped | ||||||||||
| 33 | # before the string reached Perl. Writing is the form of the ODBC class: it does | ||||||||||
| 34 | # not depend on how the value is read. | ||||||||||
| 35 | 2 | ▶ | use DBIO::MSSQL::Storage::DateTime::Format; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 2 | my $ODBC = 'DBIO::MSSQL::Storage::DateTime::Format'; | |||||||||
| 37 | |||||||||||
| 38 | 2 | ▶ | sub parse_datetime2 { shift; $ODBC->parse_datetime2(@_) } | ||||||||
|
Subroutine
parse_datetime2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 39 | 1 | ▶ | sub format_datetime2 { shift; $ODBC->format_datetime2(@_) } | ||||||||
|
Subroutine
format_datetime2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 40 | 2 | ▶ | sub parse_datetimeoffset { shift; $ODBC->parse_datetimeoffset(@_) } | ||||||||
|
Subroutine
parse_datetimeoffset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 41 | 1 | ▶ | sub format_datetimeoffset { shift; $ODBC->format_datetimeoffset(@_) } | ||||||||
|
Subroutine
format_datetimeoffset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 1 | ▶ | sub format_time { shift; $ODBC->format_time(@_) } | ||||||||
|
Subroutine
format_time: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 43 | |||||||||||
| 44 | # the date in front of a time is the client library's filler, not the time's | ||||||||||
| 45 | 2 | ▶ | sub parse_time { | ||||||||
|
Subroutine
parse_time: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||
| 46 | 2 | my ($class, $value) = @_; | |||||||||
| 47 | 2 | ▶ | $value =~ s/\A\s*\d{4}-\d\d-\d\d[ T]// if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 2 | ▶ | $value =~ s/Z\s*\z// if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 2 | return $ODBC->parse_time($value); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 2 | 1; | |||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||