Ejemplo n.º 1
0
    // public __construct ( string $timezone )
    public void __construct(string timezone_name)
    {
        if (timezone_name != null)
        {
            this.timezone = PhpTimeZone.GetTimeZone(timezone_name);

            if (this.timezone == null)
            {
                //PhpException.Throw(PhpError.Notice, LibResources.GetString("unknown_timezone", zoneName));
                throw new ArgumentException();
            }
        }
        else
        {
            this.timezone = PhpTimeZone.GetCurrentTimeZone(_ctx);
        }
    }
Ejemplo n.º 2
0
    public DateTime(Context ctx, string time, DateTimeZone timezone)
    {
        Debug.Assert(ctx != null);

        _ctx = ctx;

        if (timezone == null)
        {
            TimeZone = PhpTimeZone.GetCurrentTimeZone(ctx);
        }
        else
        {
            //var datetimezone = timezone as DateTimeZone;
            //if (datetimezone == null)
            //{
            //    PhpException.InvalidArgumentType("timezone", "DateTimeZone");
            //    TimeZone = PhpTimeZone.CurrentTimeZone;
            //}
            //else
            {
                TimeZone = timezone.timezone;
            }
        }

        if (TimeZone == null)
        {
            //PhpException.InvalidArgument("timezone");
            //return null;
            throw new ArgumentException();
        }

        this.Time = StrToTime(time, System_DateTime.UtcNow);

        //this.date.Value = this.Time.ToString("yyyy-mm-dd HH:mm:ss");
        //this.timezone_type.Value = 3;
        //this.timezone.Value = TimeZone.Id;
    }
Ejemplo n.º 3
0
    public static object createFromFormat(Context ctx, string format, string time, DateTimeZone timezone = null)
    {
        // arguments
        var tz = (timezone != null) ? timezone.timezone : PhpTimeZone.GetCurrentTimeZone(ctx);

        if (format == null)
        {
            //PhpException.InvalidArgument("format");
            //return false;
            throw new ArgumentNullException();
        }

        if (time == null)
        {
            //PhpException.InvalidArgument("time");
            //return false;
            throw new ArgumentNullException();
        }

        // create DateTime from format+time
        int i = 0;  // position in <timestr>

        foreach (var c in format)
        {
            switch (c)
            {
            //case 'd':
            //case 'j':
            //    var day = PHP.Library.StrToTime.DateInfo.ParseUnsignedInt(timestr, ref i, 2);
            //    // ... use day
            //    break;
            //case 'F':
            //case 'M':
            //    // parse  ...
            //    break;
            default:
                if (i < time.Length && time[i] == c)
                {
                    // match
                    i++;
                }
                else
                {
                    // not match
                    //PhpException.InvalidArgument("time");   // time not matching format
                    //return false;
                    throw new ArgumentException();
                }
                break;
            }
        }

        if (i < time.Length)
        {
            //PhpException.InvalidArgument("time");   // time not matching format
            //return false;
            throw new ArgumentException();
        }

        ////
        //return new __PHP__DateTime(context, true)
        //{
        //     //Time = new DateTime(year, month, day, hour, minute, second, millisecond),
        //     TimeZone = tz,
        //};

        throw new NotImplementedException();
    }