Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dev/import-perl5/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ imports:
target: perl5_t/Term-Table
type: directory

# From CPAN distribution
- source: perl5/cpan/Time-Local/lib/Time/Local.pm
target: src/main/perl/lib/Time/Local.pm

# Tests for distribution
- source: perl5/cpan/Time-Local/t
target: perl5_t/Time-Local
type: directory

# Add more imports below as needed
# Example with minimal fields:
# - source: perl5/lib/SomeModule.pm
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/org/perlonjava/backend/jvm/Dereference.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,20 +794,11 @@ public static void handleArrowArrayDeref(EmitterVisitor emitterVisitor, BinaryOp

ArrayLiteralNode right = (ArrayLiteralNode) node.right;

// Check if this is a true array literal (contains only literal elements like strings and numbers)
// and has a single range operator in the indices
boolean isArrayLiteral = node.left instanceof ArrayLiteralNode leftArray &&
leftArray.elements.stream().allMatch(elem ->
elem instanceof StringNode ||
elem instanceof NumberNode) &&
leftArray.elements.size() > 1; // Must have multiple literal elements

boolean isSingleRange = right.elements.size() == 1 &&
right.elements.getFirst() instanceof BinaryOperatorNode binOp &&
"..".equals(binOp.operator);

// Only apply the fix to true array literals with range operators
if (right.elements.size() == 1 && !(isArrayLiteral && isSingleRange)) {

if (right.elements.size() == 1 && !isSingleRange) {
// Single index: use get/delete/exists methods
Node elem = right.elements.getFirst();
elem.accept(emitterVisitor.with(RuntimeContextType.SCALAR));
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/org/perlonjava/runtime/operators/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import org.perlonjava.runtime.runtimetypes.RuntimeScalar;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -89,8 +89,8 @@ public static RuntimeList localtime(RuntimeList args, int ctx) {
if (args.isEmpty()) {
date = ZonedDateTime.now();
} else {
long arg = args.getFirst().getInt();
date = Instant.ofEpochSecond(arg).atZone(ZoneId.systemDefault());
long epoch = (long) Math.floor(args.getFirst().getDouble());
date = Instant.ofEpochSecond(epoch).atZone(ZoneId.systemDefault());
}
return getTimeComponents(ctx, date);
}
Expand All @@ -107,16 +107,24 @@ public static RuntimeList gmtime(RuntimeList args, int ctx) {
if (args.isEmpty()) {
date = ZonedDateTime.now(ZoneOffset.UTC);
} else {
long arg = args.getFirst().getInt();
date = Instant.ofEpochSecond(arg).atZone(ZoneId.of("UTC"));
long epoch = (long) Math.floor(args.getFirst().getDouble());
date = Instant.ofEpochSecond(epoch).atZone(ZoneId.of("UTC"));
}
return getTimeComponents(ctx, date);
}

private static RuntimeList getTimeComponents(int ctx, ZonedDateTime date) {
RuntimeList res = new RuntimeList();
if (ctx == RuntimeContextType.SCALAR) {
res.add(date.format(DateTimeFormatter.RFC_1123_DATE_TIME));
String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int dow = date.getDayOfWeek().getValue(); // Mon=1..Sun=7
String dayStr = days[dow - 1];
String monStr = months[date.getMonth().getValue() - 1];
int mday = date.getDayOfMonth();
String timeStr = String.format("%02d:%02d:%02d", date.getHour(), date.getMinute(), date.getSecond());
res.add(new RuntimeScalar(String.format("%s %s %2d %s %d", dayStr, monStr, mday, timeStr, date.getYear())));
return res;
}
// 0 1 2 3 4 5 6 7 8
Expand All @@ -127,7 +135,8 @@ private static RuntimeList getTimeComponents(int ctx, ZonedDateTime date) {
res.add(date.getDayOfMonth());
res.add(date.getMonth().getValue() - 1);
res.add(date.getYear() - 1900);
res.add(date.getDayOfWeek().getValue());
int dow = date.getDayOfWeek().getValue(); // Mon=1..Sun=7
res.add(dow == 7 ? 0 : dow); // Sun=0, Mon=1..Sat=6
res.add(date.getDayOfYear() - 1);
res.add(date.getZone().getRules().isDaylightSavings(date.toInstant()) ? 1 : 0);
return res;
Expand Down
Loading