Skip to content

Commit

Permalink
Merge pull request #126 from toad-dev/patch/fix-epoch-ingame
Browse files Browse the repository at this point in the history
Fix os.epoch("ingame") throwing "Unsupported operation"
  • Loading branch information
SquidDev authored Oct 22, 2022
2 parents 55625c7 + 06ee57e commit a738e36
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/java/dan200/computercraft/core/apis/OSAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public final double clock()
* Returns the current time depending on the string passed in. This will
* always be in the range [0.0, 24.0).
*
* * If called with {@code dan200.computercraft.ingame}, the current world time will be returned.
* * If called with {@code ingame}, the current world time will be returned.
* This is the default if nothing is passed.
* * If called with {@code utc}, returns the hour of the day in UTC time.
* * If called with {@code local}, returns the hour of the day in the
Expand All @@ -326,10 +326,10 @@ public final double clock()
* which will convert the date fields into a UNIX timestamp (number of
* seconds since 1 January 1970).
*
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
* @return The hour of the selected locale, or a UNIX timestamp from the table, depending on the argument passed in.
* @throws LuaException If an invalid locale is passed.
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
* @cc.see textutils.formatTime To convert times into a user-readable string.
* @cc.usage Print the current in-game time.
* <pre>{@code
Expand All @@ -347,14 +347,14 @@ public final Object time( IArguments args ) throws LuaException
Object value = args.get( 0 );
if( value instanceof Map ) return LuaDateTime.fromTable( (Map<?, ?>) value );

String param = args.optString( 0, "dan200.computercraft.ingame" );
String param = args.optString( 0, "ingame" );
switch( param.toLowerCase( Locale.ROOT ) )
{
case "utc": // Get Hour of day (UTC)
return getTimeForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
case "local": // Get Hour of day (local time)
return getTimeForCalendar( Calendar.getInstance() );
case "dan200.computercraft.ingame": // Get in-game hour
case "ingame": // Get in-game hour
return time;
default:
throw new LuaException( "Unsupported operation" );
Expand All @@ -364,14 +364,14 @@ public final Object time( IArguments args ) throws LuaException
/**
* Returns the day depending on the locale specified.
*
* * If called with {@code dan200.computercraft.ingame}, returns the number of days since the
* * If called with {@code ingame}, returns the number of days since the
* world was created. This is the default.
* * If called with {@code utc}, returns the number of days since 1 January
* 1970 in the UTC timezone.
* * If called with {@code local}, returns the number of days since 1
* January 1970 in the server's local timezone.
*
* @param args The locale to get the day for. Defaults to {@code dan200.computercraft.ingame} if not set.
* @param args The locale to get the day for. Defaults to {@code ingame} if not set.
* @return The day depending on the selected locale.
* @throws LuaException If an invalid locale is passed.
* @cc.since 1.48
Expand All @@ -380,13 +380,13 @@ public final Object time( IArguments args ) throws LuaException
@LuaFunction
public final int day( Optional<String> args ) throws LuaException
{
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
{
case "utc": // Get numbers of days since 1970-01-01 (utc)
return getDayForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
case "local": // Get numbers of days since 1970-01-01 (local time)
return getDayForCalendar( Calendar.getInstance() );
case "dan200.computercraft.ingame":// Get game day
case "ingame":// Get game day
return day;
default:
throw new LuaException( "Unsupported operation" );
Expand All @@ -396,14 +396,14 @@ public final int day( Optional<String> args ) throws LuaException
/**
* Returns the number of milliseconds since an epoch depending on the locale.
*
* * If called with {@code dan200.computercraft.ingame}, returns the number of milliseconds since the
* * If called with {@code ingame}, returns the number of milliseconds since the
* world was created. This is the default.
* * If called with {@code utc}, returns the number of milliseconds since 1
* January 1970 in the UTC timezone.
* * If called with {@code local}, returns the number of milliseconds since 1
* January 1970 in the server's local timezone.
*
* @param args The locale to get the milliseconds for. Defaults to {@code dan200.computercraft.ingame} if not set.
* @param args The locale to get the milliseconds for. Defaults to {@code ingame} if not set.
* @return The milliseconds since the epoch depending on the selected locale.
* @throws LuaException If an invalid locale is passed.
* @cc.since 1.80pr1
Expand All @@ -418,7 +418,7 @@ public final int day( Optional<String> args ) throws LuaException
@LuaFunction
public final long epoch( Optional<String> args ) throws LuaException
{
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
{
case "utc":
{
Expand All @@ -432,7 +432,7 @@ public final long epoch( Optional<String> args ) throws LuaException
Calendar c = Calendar.getInstance();
return getEpochForCalendar( c );
}
case "dan200.computercraft.ingame":
case "ingame":
// Get in-game epoch
synchronized( alarms )
{
Expand Down

0 comments on commit a738e36

Please sign in to comment.