예제 #1
0
VALUE occurrences( VALUE self, VALUE dtstart, VALUE dtend, VALUE rrule ) {
  char * _rrule;
  struct icaltimetype start, end;
  time_t tt;
  VALUE  tv_sec, occurr = rb_ary_new();

  /* Get method ID for Time.tv_sec */
  ID time_tv_sec  = rb_intern( "tv_sec" );
  ID to_string    = rb_intern( "to_string" );

  if( TYPE( rrule ) != T_STRING && rb_respond_to( rrule, to_string ) )
    rrule = rb_funcall( rrule, to_string, 0 );

  Check_Type(rrule, T_STRING);
  _rrule = RSTRING(rrule)->ptr;

  dtstart = to_time( dtstart, "dtstart" );
  dtend   = to_time( dtend,   "dtend" );

  /* Apply .tv_sec to our Time objects (if they are Times ...) */
  tv_sec = rb_funcall( dtstart, time_tv_sec, 0 );
  tt     = NUM2INT( tv_sec );
  start  = icaltime_from_timet( tt, 0 );

  tv_sec = rb_funcall( dtend, time_tv_sec, 0 );
  tt     = NUM2INT( tv_sec );
  end    = icaltime_from_timet( tt, 0 );

  icalerror_clear_errno();
  icalerror_set_error_state( ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL);

  struct icalrecurrencetype recur = icalrecurrencetype_from_string( _rrule );
  if( icalerrno != ICAL_NO_ERROR ) {
    rb_raise(rb_eArgError, "Malformed RRule");
    return Qnil;
  }

  icalrecur_iterator* ritr = icalrecur_iterator_new( recur, start );

  while(1) {
    struct icaltimetype next = icalrecur_iterator_next(ritr);

    if( icaltime_is_null_time(next) || ( icaltime_compare( next, end ) > 0 ) ) {
      icalrecur_iterator_free(ritr);
      return occurr;
    }

    rb_ary_push( occurr, rb_time_new( icaltime_as_timet( next ), 0 ) );
  };

  icalrecur_iterator_free(ritr);
  return occurr;
}
예제 #2
0
void
MainWindow::draw_spectrum()
{
    x_.clear();
    y0_.clear();

    boost::math::normal_distribution<double> nd( to_time( 500 ), to_time( 5 ) );

    double max = boost::math::pdf( nd, to_time( 500 ) );
    const int b18fs = 0x3ffff / 16;

    qDebug() << boost::math::pdf( nd, to_time( 500 ) ) / max * 100;
    qDebug() << boost::math::pdf( nd, to_time( 500 - 5 ) ) / max * 100;
    qDebug() << boost::math::pdf( nd, to_time( 500 - 10 ) ) / max * 100;

    for ( int i = 0; i < 1000; ++i ) {
        x_.push_back( to_time( i ) );
        double y = boost::math::pdf( nd, to_time( i ) ) / max;
        y0_.push_back( y );
        y1_.push_back( int( y * b18fs ) / double(b18fs) );
    }
    
    plot_->setData( &x_[0], &y0_[0], x_.size(), 0 );
    plot_->setData( &x_[0], &y1_[0], x_.size(), 1 );

    zoomer_->setZoomBase();

}
예제 #3
0
파일: File.cpp 프로젝트: zeroch/rpcs3
		void add_entry(const WIN32_FIND_DATAW& found)
		{
			dir_entry info;

			to_utf8(info.name, found.cFileName);
			info.is_directory = (found.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
			info.is_writable = (found.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
			info.size = ((u64)found.nFileSizeHigh << 32) | (u64)found.nFileSizeLow;
			info.atime = to_time(found.ftLastAccessTime);
			info.mtime = to_time(found.ftLastWriteTime);
			info.ctime = to_time(found.ftCreationTime);

			m_entries.emplace_back(std::move(info));
		}
예제 #4
0
파일: File.cpp 프로젝트: zeroch/rpcs3
static time_t to_time(const FILETIME& ft)
{
	ULARGE_INTEGER v;
	v.LowPart = ft.dwLowDateTime;
	v.HighPart = ft.dwHighDateTime;

	return to_time(v);
}
예제 #5
0
파일: File.cpp 프로젝트: zeroch/rpcs3
static time_t to_time(const LARGE_INTEGER& ft)
{
	ULARGE_INTEGER v;
	v.LowPart = ft.LowPart;
	v.HighPart = ft.HighPart;

	return to_time(v);
}
예제 #6
0
파일: File.cpp 프로젝트: zeroch/rpcs3
		stat_t stat() override
		{
			FILE_BASIC_INFO basic_info;
			if (!GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO)))
			{
				throw fmt::exception("Win32 error: %u." HERE, GetLastError());
			}

			stat_t info;
			info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
			info.is_writable = (basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
			info.size = this->size();
			info.atime = to_time(basic_info.LastAccessTime);
			info.mtime = to_time(basic_info.ChangeTime);
			info.ctime = to_time(basic_info.CreationTime);

			return info;
		}
예제 #7
0
 date_time::date_time(unsigned short y, unsigned char mon, unsigned char d, unsigned char h, unsigned char min, unsigned char s) {
     tm_type tm;
     ::memset(&tm, 0, sizeof(tm));
     tm.tm_year = y - 1900;
     tm.tm_mon = mon - 1;
     tm.tm_mday = d;
     tm.tm_hour = h;
     tm.tm_min = min;
     tm.tm_sec = s;
     time_ = to_time(tm, false);
 }
예제 #8
0
파일: cpu_timer.c 프로젝트: gfxprim/gfxprim
void cpu_timer_stop(struct cpu_timer *self)
{
	if (timers_disabled)
		return;

	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &self->t_cpu_stop);
	clock_gettime(CLOCK_MONOTONIC, &self->t_real_stop);

	int cpu_sec;
	int cpu_nsec;

	int real_sec;
	int real_nsec;

	to_time(&cpu_sec, &cpu_nsec, &self->t_cpu_start, &self->t_cpu_stop);
	to_time(&real_sec, &real_nsec, &self->t_real_start, &self->t_real_stop);

	printf("TIMER '%s' CPU=%i.%09is REAL=%i.%09is\n", self->name,
	       cpu_sec, cpu_nsec, real_sec, real_nsec);
}
예제 #9
0
파일: File.cpp 프로젝트: zeroch/rpcs3
bool fs::stat(const std::string& path, stat_t& info)
{
	if (auto device = get_virtual_device(path))
	{
		return device->stat(path, info);
	}

#ifdef _WIN32
	WIN32_FILE_ATTRIBUTE_DATA attrs;
	if (!GetFileAttributesExW(to_wchar(path).get(), GetFileExInfoStandard, &attrs))
	{
		g_tls_error = to_error(GetLastError());
		return false;
	}

	info.is_directory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
	info.is_writable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
	info.size = (u64)attrs.nFileSizeLow | ((u64)attrs.nFileSizeHigh << 32);
	info.atime = to_time(attrs.ftLastAccessTime);
	info.mtime = to_time(attrs.ftLastWriteTime);
	info.ctime = to_time(attrs.ftCreationTime);
#else
	struct ::stat file_info;
	if (::stat(path.c_str(), &file_info) != 0)
	{
		g_tls_error = to_error(errno);
		return false;
	}

	info.is_directory = S_ISDIR(file_info.st_mode);
	info.is_writable = file_info.st_mode & 0200; // HACK: approximation
	info.size = file_info.st_size;
	info.atime = file_info.st_atime;
	info.mtime = file_info.st_mtime;
	info.ctime = file_info.st_ctime;
#endif

	return true;
}
예제 #10
0
 date_time::date_time(const tm_type& tm, bool check_wday) : time_(to_time(tm, check_wday)) {}
예제 #11
0
int main(int argc, char *argv[]) {
    int opt;
    opts.current = 1;
    char r_file[PATHMAX];

    struct option longopts[] = {
        {"help", 0, NULL, 'h'},
        {"version", 0, NULL, 'V'},
        {"access", 0, NULL, 'a'},
        {"modification", 0, NULL, 'm'},
        {"nocreate", 0, NULL, 'c'},
        {"nodereference", 0, NULL, 'n'},
        {"date", required_argument, NULL, 'd'},
        {"time", required_argument, NULL, 't'},
        {"reference", required_argument, NULL, 'r'},
        {0,0,0,0}
    };

    while ((opt = getopt_long(argc, argv, "Vhacmr:t:d:", longopts, NULL)) != -1) {
        switch(opt) {
            case 'V':
                printf("%s (%s) version %s\n", APPNAME, APPSUITE, APPVERSION);
                printf("%s compiled on %s at %s\n", basename(__FILE__), __DATE__, __TIME__);
                exit(EXIT_SUCCESS);
                break;
            case 'h':
                show_help();
                exit(EXIT_SUCCESS);
            case 'a':
                opts.modification = 0;
                break;
            case 'm':
                opts.access = 0;
                break;
            case 'c':
                opts.nocreate = 1;
                break;
            case 'n':
                opts.nodereference = 1;
                break;
            case 'r':
                opts.reference = 1;
                opts.current = 0;
                strncpy(r_file, optarg, PATHMAX);
                break;
            case ':':
                 /* getopt_long prints own error message */
                exit(EXIT_FAILURE);
            case '?':
                 /* getopt_long prints own error message */
                exit(EXIT_FAILURE);
            default:
                show_help();
                exit(EXIT_FAILURE);
        }
    }

    /* populate the time struct */
    to_time(r_file);

    int fd;
    while (optind < argc) {
        fd = open(argv[optind], O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
        if (fd < 0) {
            if (errno == EEXIST) {    /* file exists */
                if (opts.current == 1) {
                    if (utimes(argv[optind], NULL) != 0)
                        perror("utimes");
                } else {
                    if (utimes(argv[optind], times) != 0)
                        perror("utimes");
                }
            } else {
                perror("touch");
            }

        } else { /* file does not exist */
            if (opts.nocreate == 1) {
                exit(EXIT_FAILURE);
            }

            if (opts.current == 1) {
                if (futimes(fd, NULL) != 0)
                    perror("futimes");
            } else {
                if (futimes(fd, times) != 0)
                    perror("futimes");
            }
        }
        optind++;
    }

    return EXIT_SUCCESS;
}
예제 #12
0
void sleep(int ms)
{
	boost::xtime delay;
	to_time(ms, delay);
	boost::thread().sleep(delay);
}