// 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); } }
public static DateTimeValue CreateFromState(Context ctx, PhpArray array) { if (array == null || array.Count == 0) { return(CreateNow(ctx)); } else { // resolve date/time var date = array.TryGetValue("date", out var dateval) && dateval.IsString(out var datestr) ? System_DateTime.Parse(datestr, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal) : System_DateTime.UtcNow; // resolve timezone or current var localtz = PhpTimeZone.GetCurrentTimeZone(ctx); if (array.TryGetValue("timezone", out var tzval) && tzval.IsString(out var tz) && tz.Length != 0) { //if (array.TryGetValue("timezone_type", out var typeval) && typeval.IsLong(out var type) && // type == 1 && // DateInfo.TryParseTimeZoneOffset(tz, 0, out var tz_minutes)) //{ // // UTC offset // localtz = DateInfo.ResolveTimeZone(tz_minutes); //} //else { // deals with any tz format localtz = PhpTimeZone.GetTimeZone(tz) ?? throw new Spl.InvalidArgumentException($"timezone:'{tz}'"); } } // if (date.Kind == DateTimeKind.Utc) { date = TimeZoneInfo.ConvertTimeFromUtc(date, localtz); } return(new DateTimeValue(date, localtz)); } }
// public __construct ( string $timezone ) public void __construct(Context ctx, string timezone_name) { if (timezone_name == null) { _timezone = PhpTimeZone.GetCurrentTimeZone(ctx); } else { var tz = PhpTimeZone.GetTimeZone(timezone_name); if (tz == null) { PhpException.Throw(PhpError.Notice, Resources.LibResources.unknown_timezone, timezone_name); throw new Spl.InvalidArgumentException(); } // _timezone = tz; _name = timezone_name; } }
public DateConfiguration() { Context.RegisterConfiguration(this); Register <DateConfiguration>("date.timezone", ExtensionName, (config) => config.TimeZoneInfo?.Id ?? string.Empty, // TODO: this is not PHP name (config, value) => { if (value.IsString(out var zoneName)) { var zone = PhpTimeZone.GetTimeZone(zoneName); if (zone != null) { config.TimeZoneInfo = zone; } else { PhpException.Throw(PhpError.Notice, Resources.LibResources.unknown_timezone, zoneName); } }
// public __construct ( string $timezone ) public void __construct(Context ctx, string timezone_name) { if (timezone_name != null) { _timezone = PhpTimeZone.GetTimeZone(timezone_name); _name = timezone_name; if (_timezone == null) { // TODO: an offset value (+0200) //PhpException.Throw(PhpError.Notice, LibResources.GetString("unknown_timezone", timezone_name)); throw new Spl.InvalidArgumentException(); } } else { _timezone = PhpTimeZone.GetCurrentTimeZone(ctx); } }