NAME

NepaliDateTime::DateTime - Bikram Sambat date + time object

SYNOPSIS

use NepaliDateTime::DateTime;

# Now in Nepal Standard Time
my $now = NepaliDateTime::DateTime->now();

# Construct
my $dt = NepaliDateTime::DateTime->new(2081, 3, 15, 14, 30, 0);

# From Unix timestamp
my $dt2 = NepaliDateTime::DateTime->from_timestamp(time());

# From AD datetime
my $dt3 = NepaliDateTime::DateTime->from_ad_datetime(2024, 7, 15, 9, 0, 0);

# Accessors
printf "%02d:%02d:%02d\n", $dt->hour, $dt->minute, $dt->second;
print  $dt->microsecond, "\n";

# Formatting
print $dt->isoformat(), "\n";              # 2081-03-15T14:30:00+05:45
print $dt->strftime('%Y-%m-%d %H:%M:%S');
print $dt->strftime_np('%K-%n-%D %h:%l:%s');  # all Devanagari

# Arithmetic
my $dt4 = $dt->add_seconds(3600);
my $dt5 = $dt->add_minutes(90);
my $dt6 = $dt + 1;   # add 1 day

# Conversion
my ($y,$m,$d,$H,$M,$S) = $dt->to_ad_datetime();
my $epoch = $dt->to_timestamp();

# Date part
my $date = $dt->date();

DESCRIPTION

NepaliDateTime::DateTime extends NepaliDateTime::Date with time components (hour, minute, second, microsecond) and Nepal Standard Time (UTC+05:45) awareness.

CONSTRUCTOR

new($year, $month, $day, $hour=0, $minute=0, $second=0, $microsecond=0)

Creates a new BS datetime. Time defaults to midnight.

CLASS METHODS

now()

Returns the current Nepal Standard Time as a NepaliDateTime::DateTime.

utcnow()

Returns the current UTC time as a NepaliDateTime::DateTime (with UTC date converted to BS, time kept as UTC).

from_timestamp($epoch, %opts)

Construct from a Unix timestamp. Converts to Nepal Standard Time by default.

my $dt = NepaliDateTime::DateTime->from_timestamp(time());

Options: utc => 1 Treat as UTC (do not add Nepal offset)

from_ad_datetime($year, $month, $day, $hour=0, $minute=0, $second=0, $microsecond=0)

Convert an AD datetime to a BS NepaliDateTime::DateTime.

my $dt = NepaliDateTime::DateTime->from_ad_datetime(2024, 7, 15, 14, 30, 0);

combine($date, $hour, $minute, $second, $microsecond)

Combine a NepaliDateTime::Date with time components.

strptime($string, $format)

Parse a BS datetime string.

my $dt = NepaliDateTime::DateTime->strptime('2081-03-15 14:30:00', '%Y-%m-%d %H:%M:%S');

min()

Minimum supported datetime (BS 1975-01-01 00:00:00).

max()

Maximum supported datetime (BS 2100-12-30 23:59:59.999999).

ACCESSORS

hour() / minute() / second() / microsecond()

date()

Returns the date part as a NepaliDateTime::Date object.

time_string()

Returns the time as "HH:MM:SS" or "HH:MM:SS.ffffff" if microseconds are non-zero.

CONVERSION

to_ad_datetime()

Returns ($year, $month, $day, $hour, $minute, $second, $microsecond) in Gregorian (AD) calendar.

to_timestamp()

Returns the Unix timestamp (seconds since 1970-01-01 00:00:00 UTC) as a float. Uses Nepal Standard Time (UTC+05:45).

utcoffset_string()

Returns the UTC offset string, e.g. "+05:45".

tzname()

Returns "NST" (Nepal Standard Time).

ARITHMETIC

All add_* methods return a new NepaliDateTime::DateTime.

add_seconds($n)

add_minutes($n)

add_hours($n)

add_days($n)

replace(%fields)

Returns a copy with specified fields replaced. Valid keys: year, month, day, hour, minute, second, microsecond.

FORMATTING

isoformat($sep)

Returns ISO-8601 string: "YYYY-MM-DDThh:mm:ss+05:45" (or with microseconds if non-zero). $sep defaults to 'T'.

strftime($format)

Same directives as "strftime" in NepaliDateTime::Date, with time directives (%H, %M, %S, %f, %I, %p) filled with the actual time.

strftime_np($format)

Convenience alias: same as strftime but reminds callers to use Devanagari format codes (%K, %n, %D, %h, %l, %s).

ctime()

Returns ctime-style string: "Wed Asa 15 14:30:00 2081".

format_devanagari()

Full Devanagari datetime string.

clone()

Returns a copy of this datetime object.

SEE ALSO

NepaliDateTime::Date