Skip to content

Instantly share code, notes, and snippets.

View warrendodsworth's full-sized avatar

Warren Dodsworth warrendodsworth

View GitHub Profile
@warrendodsworth
warrendodsworth / luxon-date-adapter.ts
Last active April 1, 2020 21:12 — forked from maburdi94/luxon-date-adapter.ts
Angular Date Adapter for Luxon - for Angular 9
import { Inject, Injectable, InjectionToken, LOCALE_ID, Optional } from '@angular/core';
import { DateAdapter } from '@angular/material/core';
import { DateTime, Info } from 'luxon';
export const DATE_LOCALE = new InjectionToken<string>('DATE_LOCALE');
/** Provider for MAT_DATE_LOCALE injection token. */
export const DATE_LOCALE_PROVIDER = { provide: DATE_LOCALE, useExisting: LOCALE_ID };
const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
@warrendodsworth
warrendodsworth / render_razor_view_to_string
Created June 22, 2017 23:38 — forked from grishin/render_razor_view_to_string
How to render razor view to string
protected string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
using (var sw = new StringWriter()) {
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}