Esempio n. 1
0
        public override bool Equals(FluidValue other)
        {
            if (other.Type == FluidValues.String && other.ToStringValue() == "")
            {
                return(true);
            }
            if (other.Type == FluidValues.Array && other.ToNumberValue() == 0)
            {
                return(true);
            }
            if (other.Type == FluidValues.Dictionary && other.ToNumberValue() == 0)
            {
                return(true);
            }
            if (other == BlankValue.Instance)
            {
                return(true);
            }
            if (other == EmptyValue.Instance)
            {
                return(true);
            }
            if (other == NilValue.Instance)
            {
                return(false);
            }

            return(false);
        }
Esempio n. 2
0
        public override bool Equals(FluidValue other)
        {
            // Delegating other types
            if (other == BlankValue.Instance || other == NilValue.Instance || other == EmptyValue.Instance)
            {
                return(false);
            }

            return(_value == other.ToNumberValue());
        }
Esempio n. 3
0
        protected override FluidValue GetIndex(FluidValue index, TemplateContext context)
        {
            var i = (int)index.ToNumberValue();

            if (i >= 0 && i < _value.Count)
            {
                return(FluidValue.Create(_value[i]));
            }

            return(NilValue.Instance);
        }
Esempio n. 4
0
        public override FluidValue GetIndex(FluidValue index, TemplateContext context)
        {
            var i = Convert.ToInt32(index.ToNumberValue());

            if (i < _value.Length)
            {
                return(Create(_value[i]));
            }

            return(NilValue.Instance);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public override bool Equals(FluidValue other)
 {
     return(_value == other.ToNumberValue());
 }