SlideShare una empresa de Scribd logo
1 de 8
DateTime Conversions
                    in

           C# .NET MVC

This short presentation will cover the basics
of using this project for DateTime
conversions in your own solution.

This is not in any way meant to be an
exhaustive coverage of the extensibility
points of C# .NET MVC that are leveraged
to make this possible.
UiDateTimeModel
The UiDateTimeModel is at the core of everything DateTime. There are a set of properties
specifically for use in the Views and a single property that is primarily used in the Server Side code.

Available Properties for use in the Views:
Views/Forms
DateTimeLocalValue        - DateTime?
LocalDate                 -String
LocalTime                 -String
TimeZoneName              -String: Required Property in ALL forms posting a UiDateTimeModel
NoSetTime                 -Bool

View Only Properties (String Properties)
LocalDateTime
LocalDateTimeAbreviatedMonthName
LocalDateTimeDayOfMonth
LocalDateTimeDayWithFullDate

Flags:
ImplicitlySet -Bool: used to indicate that either the Date or Time of the DateTimeLocalValue was set via the
                   model binding and NOT via a form post or other end user activities.

Please note that the UiDateTimeModel requires a TimeZone at the time of instantiation:
var model = new UiDateTimeTestModel { UiDateTime = new UiDateTimeModel(timeZone) { } };
UiDateTimeRangeModel
Closely related to the UiDateTimeModel and potentially used as extensively throughout many
applications is the UiDateTimeRangeModel. The two most important (and only) properties of
this model are the StartDateTime and EndDateTime which are both of type
UiDateTimeModel.
Additionally you will want to note that there are three different constructors which improve the
usability of the UiDateTimeRangeModel especially when this model must be instantiated for
mapping purposes.

Constructors:
UiDateTimeRangeModel(string timeZoneName)
UiDateTimeRangeModel(string timeZoneName, DateTime? startDateUtc, DateTime? endDateUtc)
UiDateTimeRangeModel(string timeZoneName, DateTime? startDateUtc, DateTime? endDateUtc, bool
isAllDay = false)


Please note that there is NO default constructor allowing instantiation of this model without a
TimeZone.
ValidationAttributes
    Below you will find the ValidationAttributes which will setup both the Clientside
    Unobtrusive validation and the Server side validation. They all have very
    descriptive names.

   UiDateTimeFormatDateValidation
   UiDateTimeFormatTimeValidation
   UiDateTimeGreaterThanDateAttributeOrNullValidation
   UiDateTimeGreaterThanDateAttributeValidation
   UiDateTimeGreaterThanTimeAttributeValidation
   UiDateTimeMaxLimitDateValidation
   UiDateTimeNotInFutureValidation
   UiDateTimeNotInPastValidation
   UiDateTimeRequiredIfAttributeValidation
   UiDateTimeRequiredIfAttributeValueEqualsValidation
   UiDateTimeRequiredIfAttributeValueNotEqualsValidation
   UiDateTimeRequiredIfNotAttributeValidation
   UiDateTimeRequiredValidation
ValidationAttributes
Implementation
UiDateTimeModel
     [UiDateTimeFormatDateValidation("LocalDate", ErrorMessageResourceName =
    "DateFormatValid", ErrorMessageResourceType = typeof(Resources.Validation))]

    [UiDateTimeFormatTimeValidation("LocalTime", ErrorMessageResourceName =
    "TimeFormatValid", ErrorMessageResourceType = typeof(Resources.Validation))]


    [UiDateTimeMaxLimitDateValidation("LocalDate", 50, ErrorMessageResourceName =
    "DateMustBeLessThanYearsInFuture", ErrorMessageResourceType = typeof(Resources.Validation))]
    public class UiDateTimeModel : IComparable

CampaignModel.cs
   [UiDateTimeDisplayAttribute("StartDateTime.LocalDate", "StartDate", typeof(Resources.UI) )]

    [UiDateTimeDisplayAttribute("EndDateTime.LocalDate", "EndDate", typeof(Resources.UI))]

    [UiDateTimeNotInPastValidation("StartDateTime.LocalDate", ErrorMessageResourceName =
    "DateNotInPastValid", ErrorMessageResourceType = typeof(Resources.Validation))]

    [UiDateTimeGreaterThanDateAttributeOrNullValidation("EndDateTime.LocalDate", "StartDateTime.LocalDate", f
    alse, ErrorMessageResourceName = "DateMustBeAfterDateValid", ErrorMessageResourceType =
    typeof(Resources.Validation))]
    public UiDateTimeRangeModel CampaignDateRange { get; set; }

    Note: This ValidationAttributes work the same as any other validation attributes that we use on model
    properties with one important difference. That being the extra parameter that defines the property of the
    model where a given attribute will be applied.
ValidationAttributes
Implementation continued
 By far the most commonly used attribute that you will implement is the
 UiDateTimeDisplayAttribute which is used when creating a model property
 of type UiDateTimeModel along with the set the Display Name for a given
 UiDateTimeModel property.

 As seen below we are setting the display name of
 UiDateTimeModel.LocalDate to be the Resource property
 “CancellationEffective”.


       [UiDateTimeDisplayAttribute("LocalDate", "CancellationEffective", type
 of(Resources.Admin))]
  public UiDateTimeModel CancellationEffective { get; set; }
Editor Templates
/ Views/Shared/EditorTemplates/
Date.cshtml
DateTime.cshtml
DateTimeNoSetTime.cshtml
Date_TopUnit.cshtml
RangeDateTimeNoSetTime.cshtml
RangeDateTimeToDateTime.cshtml
RangeDateTimeToTime.cshtml
RangeDateToDate.cshtml
RangeTimeToTime.cshtml
Time.cshtml
TimeNoSetTime.cshtml
UiDateTimeModel.cshtml
UiDateTimeRangeModel.cshtml
Editor Template
Implementation
ViewsSomeFile.cshtml
<div class="formrow">
@Html.EditorFor(m => m.ActionDate, "DateTimeNoSetTime", new
                                         {
                                              LocalDate = new { @class = "w75" },
                                              LocalTime = new { @class =
   "w65", disabled="disabeld" }
                                         })
</div>


ViewsActionYetAnotherFile.cshtml
@Html.EditorFor(m => m.ScheduledDateTime, "RangeDateTimeNoSetTime", new
                {
                    StartDateTime_LocalDate = new { @class = "w75", id ="ScheduledAction_Date"
   },
                    StartDateTime_LocalTime = new { @class = "w65" }
               })


   Note: In both implementations of the Editor Templates above the third property of the
   template defines and HTML object that will be used to add additional attributes to the
   model property defined.

Más contenido relacionado

Último

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

C# ASP.Net MVC DateTime Conversions

  • 1. DateTime Conversions in C# .NET MVC This short presentation will cover the basics of using this project for DateTime conversions in your own solution. This is not in any way meant to be an exhaustive coverage of the extensibility points of C# .NET MVC that are leveraged to make this possible.
  • 2. UiDateTimeModel The UiDateTimeModel is at the core of everything DateTime. There are a set of properties specifically for use in the Views and a single property that is primarily used in the Server Side code. Available Properties for use in the Views: Views/Forms DateTimeLocalValue - DateTime? LocalDate -String LocalTime -String TimeZoneName -String: Required Property in ALL forms posting a UiDateTimeModel NoSetTime -Bool View Only Properties (String Properties) LocalDateTime LocalDateTimeAbreviatedMonthName LocalDateTimeDayOfMonth LocalDateTimeDayWithFullDate Flags: ImplicitlySet -Bool: used to indicate that either the Date or Time of the DateTimeLocalValue was set via the model binding and NOT via a form post or other end user activities. Please note that the UiDateTimeModel requires a TimeZone at the time of instantiation: var model = new UiDateTimeTestModel { UiDateTime = new UiDateTimeModel(timeZone) { } };
  • 3. UiDateTimeRangeModel Closely related to the UiDateTimeModel and potentially used as extensively throughout many applications is the UiDateTimeRangeModel. The two most important (and only) properties of this model are the StartDateTime and EndDateTime which are both of type UiDateTimeModel. Additionally you will want to note that there are three different constructors which improve the usability of the UiDateTimeRangeModel especially when this model must be instantiated for mapping purposes. Constructors: UiDateTimeRangeModel(string timeZoneName) UiDateTimeRangeModel(string timeZoneName, DateTime? startDateUtc, DateTime? endDateUtc) UiDateTimeRangeModel(string timeZoneName, DateTime? startDateUtc, DateTime? endDateUtc, bool isAllDay = false) Please note that there is NO default constructor allowing instantiation of this model without a TimeZone.
  • 4. ValidationAttributes Below you will find the ValidationAttributes which will setup both the Clientside Unobtrusive validation and the Server side validation. They all have very descriptive names.  UiDateTimeFormatDateValidation  UiDateTimeFormatTimeValidation  UiDateTimeGreaterThanDateAttributeOrNullValidation  UiDateTimeGreaterThanDateAttributeValidation  UiDateTimeGreaterThanTimeAttributeValidation  UiDateTimeMaxLimitDateValidation  UiDateTimeNotInFutureValidation  UiDateTimeNotInPastValidation  UiDateTimeRequiredIfAttributeValidation  UiDateTimeRequiredIfAttributeValueEqualsValidation  UiDateTimeRequiredIfAttributeValueNotEqualsValidation  UiDateTimeRequiredIfNotAttributeValidation  UiDateTimeRequiredValidation
  • 5. ValidationAttributes Implementation UiDateTimeModel [UiDateTimeFormatDateValidation("LocalDate", ErrorMessageResourceName = "DateFormatValid", ErrorMessageResourceType = typeof(Resources.Validation))] [UiDateTimeFormatTimeValidation("LocalTime", ErrorMessageResourceName = "TimeFormatValid", ErrorMessageResourceType = typeof(Resources.Validation))] [UiDateTimeMaxLimitDateValidation("LocalDate", 50, ErrorMessageResourceName = "DateMustBeLessThanYearsInFuture", ErrorMessageResourceType = typeof(Resources.Validation))] public class UiDateTimeModel : IComparable CampaignModel.cs [UiDateTimeDisplayAttribute("StartDateTime.LocalDate", "StartDate", typeof(Resources.UI) )] [UiDateTimeDisplayAttribute("EndDateTime.LocalDate", "EndDate", typeof(Resources.UI))] [UiDateTimeNotInPastValidation("StartDateTime.LocalDate", ErrorMessageResourceName = "DateNotInPastValid", ErrorMessageResourceType = typeof(Resources.Validation))] [UiDateTimeGreaterThanDateAttributeOrNullValidation("EndDateTime.LocalDate", "StartDateTime.LocalDate", f alse, ErrorMessageResourceName = "DateMustBeAfterDateValid", ErrorMessageResourceType = typeof(Resources.Validation))] public UiDateTimeRangeModel CampaignDateRange { get; set; } Note: This ValidationAttributes work the same as any other validation attributes that we use on model properties with one important difference. That being the extra parameter that defines the property of the model where a given attribute will be applied.
  • 6. ValidationAttributes Implementation continued By far the most commonly used attribute that you will implement is the UiDateTimeDisplayAttribute which is used when creating a model property of type UiDateTimeModel along with the set the Display Name for a given UiDateTimeModel property. As seen below we are setting the display name of UiDateTimeModel.LocalDate to be the Resource property “CancellationEffective”. [UiDateTimeDisplayAttribute("LocalDate", "CancellationEffective", type of(Resources.Admin))] public UiDateTimeModel CancellationEffective { get; set; }
  • 8. Editor Template Implementation ViewsSomeFile.cshtml <div class="formrow"> @Html.EditorFor(m => m.ActionDate, "DateTimeNoSetTime", new { LocalDate = new { @class = "w75" }, LocalTime = new { @class = "w65", disabled="disabeld" } }) </div> ViewsActionYetAnotherFile.cshtml @Html.EditorFor(m => m.ScheduledDateTime, "RangeDateTimeNoSetTime", new { StartDateTime_LocalDate = new { @class = "w75", id ="ScheduledAction_Date" }, StartDateTime_LocalTime = new { @class = "w65" } }) Note: In both implementations of the Editor Templates above the third property of the template defines and HTML object that will be used to add additional attributes to the model property defined.