You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							51 lines
						
					
					
						
							1.5 KiB
						
					
					
				
			
		
		
	
	
							51 lines
						
					
					
						
							1.5 KiB
						
					
					
				| package NGCP::Schema::InflateColumn::DateTime::EpochMilli;
 | |
| 
 | |
| use Sipwise::Base '-skip'=>['TryCatch'];
 | |
| use DateTime qw();
 | |
| 
 | |
| use parent 'DBIx::Class';
 | |
| 
 | |
| our $VERSION = '2.007';
 | |
| 
 | |
| __PACKAGE__->load_components(qw(InflateColumn::DateTime));
 | |
| 
 | |
| # back compat
 | |
| sub add_columns {
 | |
|     my ($class, @cols) = @_;
 | |
|     my @columns;
 | |
|     while (my $col = shift @cols) {
 | |
|         my $info = ref $cols[0] ? shift @cols : {};
 | |
|         if( my $type = delete $info->{ epoch_milli } ) {
 | |
|             $info->{ inflate_datetime } = 'epoch_milli';
 | |
|             if( $type =~ m{^[cm]time$} ) {
 | |
|                 __PACKAGE__->load_components( 'TimeStamp' );
 | |
|                 $info->{ set_on_create } = 1;
 | |
|                 $info->{ set_on_update } = 1 if $type eq 'mtime';
 | |
|             }
 | |
|         }
 | |
|         push @columns, $col => $info;
 | |
|     }
 | |
|     $class->next::method(@columns);
 | |
| }
 | |
| 
 | |
| sub _inflate_to_datetime {
 | |
|     my ($self, $value, $info, @rest) = @_;
 | |
|     return $self->next::method($value, $info, @rest)
 | |
|       unless $info->{data_type} eq "decimal"
 | |
|           || (exists $info->{inflate_datetime}
 | |
|           && $info->{inflate_datetime} eq 'epoch_milli');
 | |
|     my $tz = DateTime::TimeZone->new( name => 'local' );
 | |
|     return DateTime->from_epoch(epoch => $value, time_zone => $tz);
 | |
| }
 | |
| 
 | |
| sub _deflate_from_datetime {
 | |
|     my ($self, $value, $info, @rest) = @_;
 | |
|     return $self->next::method($value, $info, @rest)
 | |
|       unless $info->{data_type} eq "decimal"
 | |
|           || (exists $info->{inflate_datetime}
 | |
|           && $info->{inflate_datetime} eq 'epoch_milli');
 | |
|     return $value->hires_epoch;
 | |
| }
 | |
| 
 | |
| 1;
 |