mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 08:38:17 +00:00
dd61a23829
This reapplies fixed versions of commit 7542 and commit 8544. Original review URLs: https://chromiumcodereview.appspot.com//10533068 https://chromiumcodereview.appspot.com//10544109 Review URL: https://chromiumcodereview.appspot.com//10534114 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8655 260f80e4-7a28-3924-810f-c04153c831b5
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include <time.h>
|
|
|
|
#include "vm/bootstrap_natives.h"
|
|
|
|
#include "vm/bigint_operations.h"
|
|
#include "vm/native_entry.h"
|
|
#include "vm/object.h"
|
|
#include "vm/os.h"
|
|
|
|
namespace dart {
|
|
|
|
static int32_t kMaxAllowedSeconds = 2100000000;
|
|
|
|
DEFINE_NATIVE_ENTRY(DateNatives_timeZoneName, 1) {
|
|
GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
|
|
int64_t seconds = dart_seconds.AsInt64Value();
|
|
if (seconds < 0 || seconds > kMaxAllowedSeconds) {
|
|
GrowableArray<const Object*> args;
|
|
args.Add(&dart_seconds);
|
|
Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
|
|
}
|
|
const char* name = OS::GetTimeZoneName(seconds);
|
|
const String& dart_name = String::Handle(String::New(name));
|
|
arguments->SetReturn(dart_name);
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(DateNatives_timeZoneOffsetInSeconds, 1) {
|
|
GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
|
|
int64_t seconds = dart_seconds.AsInt64Value();
|
|
if (seconds < 0 || seconds > kMaxAllowedSeconds) {
|
|
GrowableArray<const Object*> args;
|
|
args.Add(&dart_seconds);
|
|
Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
|
|
}
|
|
int offset = OS::GetTimeZoneOffsetInSeconds(seconds);
|
|
const Integer& dart_offset = Integer::Handle(Integer::New(offset));
|
|
arguments->SetReturn(dart_offset);
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(DateNatives_localTimeZoneAdjustmentInSeconds, 0) {
|
|
int adjustment = OS::GetLocalTimeZoneAdjustmentInSeconds();
|
|
const Integer& dart_adjustment = Integer::Handle(Integer::New(adjustment));
|
|
arguments->SetReturn(dart_adjustment);
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) {
|
|
const Integer& time = Integer::Handle(
|
|
Integer::New(OS::GetCurrentTimeMillis()));
|
|
arguments->SetReturn(time);
|
|
}
|
|
|
|
} // namespace dart
|