Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
DateTime::createFromFormat, date_create_from_format stubs
Browse files Browse the repository at this point in the history
- needs to be implemented

git-tfs-id: [http://falcon:8080/tfs/Projects]$/Phalanger/Main;C3677
  • Loading branch information
jakubmisek committed Nov 8, 2012
1 parent e96fd47 commit bb42441
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions Source/ClassLibrary/DateTime.CLR/DateTime.cs
Expand Up @@ -266,6 +266,83 @@ public static object modify(object instance, PhpStack stack)
stack.RemoveFrame();

return ((__PHP__DateTime)instance).modify(stack.Context, modify);
}

[ImplementsMethod]
public static object createFromFormat(ScriptContext/*!*/context, object format, object time, [Optional]object timezone)
{
// arguments
var tz = (timezone is DateTimeZone) ? ((DateTimeZone)timezone).timezone : PhpTimeZone.CurrentTimeZone;
string formatstr = PhpVariable.AsString(format);
string timestr = PhpVariable.AsString(time);

if (formatstr == null)
{
PhpException.InvalidArgument("format");
return false;
}

if (timestr == null)
{
PhpException.InvalidArgument("time");
return false;
}

// create DateTime from format+time
int i = 0; // position in <timestr>
foreach (var c in formatstr)
{
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 < timestr.Length && timestr[i] == c)
{
// match
i++;
}
else
{
// not match
PhpException.InvalidArgument("time"); // time not matching format
return false;
}
break;
}
}

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

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

throw new NotImplementedException();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public static object createFromFormat(object instance, PhpStack stack)
{
var format = stack.PeekValue(1);
var time = stack.PeekValue(2);
var timezone = stack.PeekValueOptional(3);
stack.RemoveFrame();
return createFromFormat(stack.Context, format, time, timezone);
}

#endregion
Expand Down Expand Up @@ -370,6 +447,33 @@ public static object DateCreate(ScriptContext/*!*/context, string time, DateTime
return dt;
}

/// <summary>
/// Returns new DateTime object formatted according to the specified format.
/// </summary>
/// <param name="format">The format that the passed in string should be in.</param>
/// <param name="time">String representing the time.</param>
/// <returns></returns>
[ImplementsFunction("date_create_from_format")]
[return: CastToFalse]
public static __PHP__DateTime DateCreateFromFormat(ScriptContext/*!*/context, string format, string time)
{
return __PHP__DateTime.createFromFormat(context, format, time, Arg.Default) as __PHP__DateTime;
}

/// <summary>
/// Returns new DateTime object formatted according to the specified format.
/// </summary>
/// <param name="format">The format that the passed in string should be in.</param>
/// <param name="time">String representing the time.</param>
/// <param name="timezone">A DateTimeZone object representing the desired time zone.</param>
/// <returns></returns>
[ImplementsFunction("date_create_from_format")]
[return:CastToFalse]
public static __PHP__DateTime DateCreateFromFormat(ScriptContext/*!*/context, string format, string time, DateTimeZone timezone)
{
return __PHP__DateTime.createFromFormat(context, format, time, timezone) as __PHP__DateTime;
}

/// <summary>
/// Alias of DateTime::getOffset().
/// </summary>
Expand Down

0 comments on commit bb42441

Please sign in to comment.