FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler
A property handler that maps the Firebird TIMESTAMP WITH TIME ZONE type into a DateTimeOffset property.
A property handler that maps the Firebird TIMESTAMP WITH TIME ZONE type into a DateTimeOffset property. The UTC offset is kept, but the name of the time zone is not.
A
DateTimeOffsetkeeps the UTC offset, but it cannot hold the name of the time zone (for exampleAmerica/New_York). Use anFbZonedDateTimeproperty when the time zone name matters.
Overview
| Name | Description |
|---|---|
| Class | FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.Firebird |
| Package | RepoDb.Firebird |
| Implements | IPropertyHandler<object, DateTimeOffset> |
| Column type | The Firebird TIMESTAMP WITH TIME ZONE type |
| Property type | DateTimeOffset |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver (a DateTimeOffset or an FbZonedDateTime) into a DateTimeOffset holding the local value and the UTC offset of the time zone. null and DBNull are returned as default. |
| Set | Property to database | Passes the DateTimeOffset to the driver, which binds it as a TIMESTAMP WITH TIME ZONE value. |
Exceptions
| Exception | Thrown When |
|---|---|
InvalidOperationException |
The UTC offset of the time zone cannot be determined. |
ArgumentException |
The type of the value returned by the driver is not supported. |
Usability
Bind the handler to the property that maps to a TIMESTAMP WITH TIME ZONE column.
Attribute
public class Appointment
{
public int Id { get; set; }
[Map("starts_at"), PropertyHandler(typeof(FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler))]
public DateTimeOffset StartsAt { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new FbConnection(connectionString))
{
connection.Insert(new Appointment { Id = 1, StartsAt = new DateTimeOffset(2026, 9, 20, 14, 30, 0, TimeSpan.FromHours(2)) });
var appointment = connection.Query<Appointment>(e => e.Id == 1).First();
// appointment.StartsAt keeps the +02:00 offset
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Appointment>()
.PropertyHandler<FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler>(e => e.StartsAt);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Appointment, FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler>(e => e.StartsAt, new FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type DateTimeOffset:
PropertyHandlerMapper.Add<DateTimeOffset, FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler>(new FirebirdZonedDateTimeToDateTimeOffsetPropertyHandler(), true);
A type level mapping is process-wide: it is applied to every
DateTimeOffsetproperty of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless everyDateTimeOffsetproperty maps to aTIMESTAMP WITH TIME ZONEcolumn.