public override bool Equals(FluidValue other) { if (other == this) { return(true); } if (other == BooleanValue.False) { return(true); } if (other == EmptyValue.Instance) { return(true); } if (other.ToObjectValue() == null) { return(true); } if (other.Type == FluidValues.String && string.IsNullOrWhiteSpace(other.ToStringValue())) { return(true); } return(false); }
public override bool Contains(FluidValue value) { foreach (var key in _value.Keys) { if (_value.TryGetValue(key, out var item) && item.Equals(value.ToObjectValue())) { return(true); } } return(false); }
public override bool Equals(FluidValue other) { if (other == EmptyValue.Instance) { return(false); } if (other == NilValue.Instance || other == BlankValue.Instance) { return(true); } return(other.ToObjectValue() == null); }
public static bool TryGetDateTimeInput(this FluidValue input, TemplateContext context, out DateTimeOffset result) { result = context.Now(); if (input.Type == FluidValues.String) { var stringValue = input.ToStringValue(); if (stringValue == Now || stringValue == Today) { return(true); } else { var success = true; if (!DateTime.TryParseExact(stringValue, DefaultFormats, context.CultureInfo, DateTimeStyles.None, out var dateTime)) { if (!DateTime.TryParseExact(stringValue, SecondaryFormats, context.CultureInfo, DateTimeStyles.None, out dateTime)) { if (!DateTime.TryParse(stringValue, context.CultureInfo, DateTimeStyles.None, out dateTime)) { if (!DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) { success = false; } } } } // If no timezone is specified, assume local using the configured timezone if (success) { if (dateTime.Kind == DateTimeKind.Unspecified) { result = new DateTimeOffset(dateTime, context.TimeZone.GetUtcOffset(dateTime)); } else { result = new DateTimeOffset(dateTime); } } return(success); } } else if (input.Type == FluidValues.Number) { var dateTime = DateTimeOffset.FromUnixTimeSeconds((long)input.ToNumberValue()); result = dateTime.ToOffset(context.TimeZone.GetUtcOffset(dateTime)); } else if (input.Type == FluidValues.DateTime) { result = (DateTimeOffset)input.ToObjectValue(); } else { switch (input.ToObjectValue()) { case DateTime dateTime: result = dateTime; break; case DateTimeOffset dateTimeOffset: result = dateTimeOffset; break; default: return(false); } } return(true); }
public override bool Contains(FluidValue value) { return(_value.Contains(value.ToObjectValue())); }